Results 1 to 3 of 3
Thread: JPane .setLocation()
- 09-06-2012, 12:43 PM #1
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();
But it doesn't work with the labels I would like to have next to it.
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.
// 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);Java 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);Java 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);
- 09-06-2012, 02:08 PM #2Moderator
- Join Date
- Apr 2009
- Rep Power
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.Please do not ask for code as refusal often offends.
- 09-06-2012, 07:03 PM #3
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- By niba10 in forum AWT / SwingReplies: 3Last Post: 07-16-2012, 08:57 PM
- By danpotter in forum AWT / SwingReplies: 7Last Post: 05-08-2012, 06:47 PM
- By OllyHal in forum AWT / SwingReplies: 1Last Post: 02-10-2012, 08:52 PM
- By xna in forum New To JavaReplies: 3Last Post: 11-11-2009, 04:29 AM
- By ScottVal in forum AWT / SwingReplies: 7Last Post: 01-13-2009, 07:35 AM