-
JPane .setLocation()
I have this GUI I made.
It is a window with on the left side 4 buttons. (and then on on the below part of the screen I have 2 more buttons. (6 buttons total))
Now I would like to add text next to the 4 buttons, but I have problems doing that.
For the buttons I used: button.setLocation();
Like: button1.setLocation(0,0);
button2.setLocation(0,50);
etc.
But it doesn't work with the labels I would like to have next to it.
label1.setLocation(50,0);
It doesn't do anything. :^):
Can anyone maybe help with that.
This is also some of the code I made about these buttons and labels.
Code:
// Create a Panel that contains the title and basic information.
titlePanelMain = new JPanel();
titlePanelMain.setLayout(null);
titlePanelMain.setLocation(10, 0);
titlePanelMain.setSize(300, 50);
totalGUI.add(titlePanelMain);
Code:
// Create a Panel that contains all Buttons.
buttonPanelMain = new JPanel();
buttonPanelMain.setLayout(null);
buttonPanelMain.setLocation(10, 80);
buttonPanelMain.setSize(750, 250);
totalGUI.add(buttonPanelMain);
// Create a Button, button1.
button1 = new JButton("Select file ");
button1.setLocation(0, 0);
button1.setSize(120, 30);
button1.addActionListener(this);
buttonPanelMain.add(button1);
Code:
// Create a Panel that contains all Labels.
labelPanelMain = new JPanel();
labelPanelMain.setLayout(null);
labelPanelMain.setLocation(0, 0);
labelPanelMain.setSize(750, 250);
totalGUI.add(labelPanelMain);
// Create a Label, label1.
label1 = new JLabel("Select a file");
label1.setLocation(140, 40);
label1.setSize(400, 30);
label1.setHorizontalAlignment(0);
labelPanelMain.add(label1);
-
Re: JPane .setLocation()
I really would suggest using proper layouts, rather than trying to position everything on the screen like that.
It's a lot quicker once you grasp the concepts.
-
Re: JPane .setLocation()
Moved from Advanced Java.
First off, this isn't by any stretch of the imagination an advanced topic. Second, I would expect someone who has been a member for near on two years and has made 130 posts to be aware of this section for AWT/Swing questions.
Tolls has already recommended the best approach; I have nothing more to add on that account.
db