I am working on Java Swing now , but as you can see in the picture below , I cannot resize(increase width) my textarea box . It only resizes if I change the width of outer jframe or if I maximise the window. Please help.
JFrame jframe = new JFrame("Java Tryout");
jframe.setSize(500, 400);
jframe.setLayout(new GridLayout());
jframe.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
});
JLabel headerLabel = new JLabel( "", JLabel.LEFT );
JLabel statusLabel = new JLabel( "", JLabel.LEFT );
statusLabel.setSize(350, 100);
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
jframe.add(headerLabel);
jframe.add(controlPanel);
jframe.add(statusLabel);
jframe.setVisible(true);
This is my code. Am I doing anything wrong?
Use some other layout, one that respects component sizes. Than you can use setMaximumSize, setMinimumSize, setPerferredSize and setSize. I suggest you use something like BoxLayout or GridBagLayout. A useful link: A visual guild to layouts
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.