Results 1 to 3 of 3
  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default 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.

    Java 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);
    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);

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default 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.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,421
    Rep Power
    20

    Default 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. add scroller on jpane
    By niba10 in forum AWT / Swing
    Replies: 3
    Last Post: 07-16-2012, 09:57 PM
  2. Layout Vs Setbounds or setlocation problem..
    By danpotter in forum AWT / Swing
    Replies: 7
    Last Post: 05-08-2012, 07:47 PM
  3. Jtable size of JPane
    By OllyHal in forum AWT / Swing
    Replies: 1
    Last Post: 02-10-2012, 09:52 PM
  4. control setLocation setBounds
    By xna in forum New To Java
    Replies: 3
    Last Post: 11-11-2009, 05:29 AM
  5. setLocation on a JDialog is ignored
    By ScottVal in forum AWT / Swing
    Replies: 7
    Last Post: 01-13-2009, 08:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •