Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I need a label, a textfield and a button in 2 rows. I used flow layout for that. But after adding all components to the Jpanel which inherits JFrame, only 2nd row is displayed. Please help where am going wrong and I am very new to Java Swing.

Thanks in advance

What I have tried:

//This inherits JFrame

FlowLayout flowLayout=new FlowLayout();
JPanel pCfgFileControl=new JPanel();
pCfgFileControl.setLayout(flowLayout);
flowLayout.setAlignment(FlowLayout.TRAILING);

pCfgFileControl.add(new JButton("Button 1"));
pCfgFileControl.add(new JButton("Button 2"));
pCfgFileControl.add(new JButton("Button 3"));
pCfgFileControl.add(new JButton("Long-Named Button 4"));
pCfgFileControl.add(new JButton("5"));
pCfgFileControl.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

JPanel pLogFileControls = new JPanel();
pLogFileControls.setLayout(new FlowLayout());

pLogFileControls.add(new JButton("Button 1"));
pLogFileControls.add(new JButton("Button 2"));
pLogFileControls.add(new JButton("Button 3"));
pLogFileControls.add(new JButton("Long-Named Button 4"));
pLogFileControls.add(new JButton("5"));

add(pCfgFileControl, BorderLayout.NORTH);
add(pLogFileControls, BorderLayout.NORTH);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900