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...

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    Updated the thread title.
  • rahul69
    rahul69
    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
    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
    }

You are reading an archived discussion.

Related Posts

I've been flipping the pages on the Internet to find out whether the recently launched MacBook Pro 13" has been launched in India. I just got an email from Apple...
It seems that the Android 4.1 Jelly Bean is rolling out for the Galaxy S3 phones in India. The firmware is being made available through Kies software and also over...
Study conducted by Ericsson ConsumerLab shows that an average of 1 hour and 7 minutes are spent by the Generation z [youngsters between 9 - 18 ] on Facebook. Approximately...
Just wondering whether anyone among CEans have bought the iPhone 5. There've been rumors that the phone got sold out on the very first day of the launch. But it...
Chinese computer maker Lenovo has become the worlds #1 laptop maker in the world. Contrary to the belief that the PC market is dying, Lenovo has proved the trend wrong....