View Feed
group-icon
Java Developers
Community of Java Developers: Get Java Programming Help from fellow Java Developers across the world.
654 Members
Join this group to post and comment.
theAvinash
theAvinash • Nov 8, 2012

Java : Need help arranging the controls according to frame size

I have created a frame..see uploaded file...if we resize it ..I want controls (labels,textboxes,button) arranged properly and size according to frame size...
Control's size should be arranged as per frame's current size..
and i want to do same with controls of all frames ....how can I do it...help me with code...
Kaustubh Katdare
Kaustubh Katdare • Nov 8, 2012
Updated the thread title.
rahul69
rahul69 • Nov 12, 2012
Hi, for resizing the controls, u should first get the current size of window, whenever the size is changed and then adjust the size of all controls with respect to the current size.
Also plz show the code u attempted, if u want to get help with the code.😀
ultimatechange
ultimatechange • Nov 22, 2012
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;

public class abc extends JFrame implements ActionListener
{

JButton b1;
JLabel l1, l2;
JTextField t1, t2;

public abc()
{
setTitle("WELCOME"); //Title for JFrame
setLayout(null);
//YOU CAN ALSO do
setResizable(false); //i.e Disabling JFrame resizing- Maximize button is DISABLED & also cannot manually resize window using mouse

l1= new JLabel("jLabel1");
t1= new JTextField(25);
l1.setBounds(85,100,100,20); // setting the location of LABEL1
t1.setBounds(150,100,200,20); // setting the location of Field1

l2= new JLabel("jLabel2");
t2= new JTextField(25);
l2.setBounds(85,130,100,20); // setting the location of LABEL2
t2.setBounds(150,130,200,20); // setting the location of Field2

//b1= new JButton("jButton1");
b1.setBounds(165,170,80,20); // setting the location of BUTTON

add(l1);
add(t1);
add(l2);
add(t2);
add(b1);

setSize(500,400); //Set JFrame size
setVisible(true); //Make JFrame visible. So we can see it.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set default close operation for JFrame

b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str = ae.getActionCommand();
// your events .............................mention here
}
public static void main(String args[])
{
new abc();
}
}


In case need any further help, just let me know
}

Share this content on your social channels -