How to display components at defined position in JPanel?
I need to display components at specific location. I'm trying to display
JLabel like,
label1:
label2:
The code below however, displays them like,
label1 : label2:
JFrame myFrame = new JFrame("My Frame");
Container container = myFrame.getContentPane();
JPanel jPanel=new JPanel(new FlowLayout(FlowLayout.LEFT));
//jPanel.setLayout(null);
JLabel jLabel1=new JLabel("Label 1 : ");
JLabel jLabel2=new JLabel("Label 2 : ");
jLabel1.setLocation(10, 50);
jLabel2.setLocation(10, 80);
jPanel.add(jLabel1);
jPanel.add(jLabel2);
myFrame.setVisible(true);
myFrame.setResizable(false);
container.add(jPanel);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.pack();
If the jPanel.setLayout(null); method is called then, it displays nothing
on the JFrame.
How to display components at a given location in JPanel?
No comments:
Post a Comment