1. Home >
  2. Apps >
  3. Groups >

Java : Need help arranging the controls according to frame size

Question asked by theAvinash in #Java on Nov 8, 2012
theAvinash · Nov 8, 2012
Rank D2 - MASTER
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... Posted in: #Java
Kaustubh Katdare
Kaustubh Katdare · Nov 8, 2012
Rank A1 - PRO
Updated the thread title.
rahul69 · Nov 12, 2012
Rank B2 - LEADER
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 · Nov 22, 2012
Rank D3 - MASTER
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
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


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

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 must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up