0

how to get non resizable frame in gui i confused about this because i am using setLayout(new FlowLayout()); so if i drag the size of the frame the location of my button is going to disarrange . here is my code so far

import java.awt.*;
import javax.swing.*;
public class aw extends JFrame
{
    private JTextField aw1;
    private JLabel aww;
    private JButton aw2;

    public aw()
    {
        setLayout(new FlowLayout());


        aww = new JLabel("Enter Your Password");
        add(aww);

        aw1 = new JTextField(15);
        add(aw1);

        aw2 = new JButton("Enter");
        add(aw2);
    }
    public static void main(String args [])
    {
        aw v = new aw();

            v.setSize(200,200);
            v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            v.setVisible(true);
    }
}
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Batusai
  • 149
  • 1
  • 1
  • 12

2 Answers2

4

I think setResizable(false) is what you're looking for

SIDE NOTES

  • Also, instead of setSize(). You should just pack() the frame. You can use EmptyBorders if you want empty space.

  • If you wanted the frame to be re-sizable and you want all the components centered when resizing, You could always wrap them all in a JPanel, then add the JPanel to the frame.

  • Use Java naming convention. Class names start with capital letters.

  • Run Swing apps form the Event Dispatch Thread, see Initial Threads

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • @CoderShei I don't see any difference in the accepted answer that would warrant the un-accepting of this one in exchange for that one. The _only_ difference is that it was answered _after_ you already accepted this one. Other than that it looks no more than what my answer _already_ provided. – Paul Samsotha Feb 11 '14 at 06:02
2

Put all the content into a JPanel, that would let you configure the pack() element, please ensure that you use an Empty Border. In the Object we have an accesor by setResizable set it to false.

Keep a note of rest and then use a Singleton thread model to run the Event-Dispatch Thread.

Thanks to AndrewThompson for his extra-ordinary knowledge that I was able to make the necessary updates

D3X
  • 547
  • 3
  • 20