I am trying to place a series of JLabels at specific X and Y coordinates on a JPanel (and also set its height and width). No matter what I do, each shortcut immediately ends to the right of the previous shortcut and is the same size as the rest.
Right now, my Jpanel is in a grid layout. I tried Absolute Layout (illegal results of excluding arguments), Free Design (without shortcuts), Flow Layout (everything just shrinks to the center) and several others.
Not sure what I need to do to make this work. Can anyone help? Thanks!
JLabel lbl1 = new JLabel("label 1"); JLabel lbl2 = new JLabel("label 2"); JLabel lbl3 = new JLabel("label 3"); JLabel lbl4 = new JLabel("label 4"); JLabel lbl5 = new JLabel("label 5"); myPanel.add(lbl1); myPanel.add(lbl2); myPanel.add(lbl3); myPanel.add(lbl4); myPanel.add(lbl5); lbl1.setLocation(27, 20); lbl2.setLocation(123, 20); lbl3.setLocation(273, 20); lbl4.setLocation(363, 20); lbl5.setLocation(453, 20); lbl1.setSize(86, 14); lbl2.setSize(140, 14); lbl3.setSize(80, 14); lbl4.setSize(80, 14); lbl5.setSize(130, 14);
java layout swing jcomponent
Alex
source share