Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Layout manager

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Layout manager

    Hello

    Im trying to create a layout which
    - has two panels one on top of the other
    -in the first panel a label on the top line at the left hand side
    -then a list of buttons on the second lines
    -the second panel the same but different buttons and label

    so far a have created a frame and a main panel (because i keep getting errors when adding a layout to a frame), the main panel has box layout.

    then i had two panels which has the label and buttons on using flowlayout. but i cant get flow layout to force onto the next line. i also tried this with GridLayout.

    so i created another panel for the labels and even if i set the size of the labelPanel to small, it takes up 50% of the frame.
    the panels with the buttons are fine using flowlayout.

    im getting confused with the layouts of the labels and im wondering if anybody can help me sort this.

    Thanks
    Kurt


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Layout manager

    If you want help with code, you'll have to provide the code. Make sure it's in SSCCE form (that's a link, but the gist is: make it as short as possible while still demonstrating what you're trying to do), and make sure you use the code tags.

    I'm not sure I understand what you're trying to do. What do you mean when you say "i cant get flow layout to force onto the next line"?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Nov 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Layout manager

    Right sorry i should of provided something

    Firstly i have created 4 panels.
    1 for the background
    1 for the label
    1 each for the set of buttons

    i also add box layout to the background (MainPanel) and add it to the frame

    MainPanel = new JPanel();
        LabelPanel = new JPanel();
            DualsPanel = new JPanel();
            SinglesPanel = new JPanel();
     
         MainPanel.setLayout( new BoxLayout(MainPanel, BoxLayout.Y_AXIS) ); //*** Creates box layout ***
            this.add(MainPanel);
     
    LabelPanel.setLayout( new BoxLayout(LabelPanel, BoxLayout.X_AXIS) ); //*** Creates box layout ***
            Dektek = new JLabel("DekDuals");
            MainPanel.add(LabelPanel);
            LabelPanel.add(Dektek);

    I then set the labelPanel to box layout too and add a label.
    This bit adds the label too the panel but in the middle and i would like it to the left. (i have tried X_AXIS, PAGE_AXIS and LINE_AXIS - none seem to work)

    and then i add the buttons to each Panel

    for (int i =o ; i < 10 ; i++) {
          btn = CreateBtn(BtnName);
          DualsPanel.add(btn);
          SinglesPanel.add(btn);
     
    }

    so i would like the LabelPanel label at the left hand side and only the high of the label (or maybe + 2/3 pxs)

    thanks
    Kurt

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Layout manager

    Again, I'm not sure what your code is doing since it's not an SSCCE. But you should probably give this a read: How to Use BoxLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. float based layout manager?
    By deepthought in forum AWT / Java Swing
    Replies: 1
    Last Post: January 1st, 2011, 10:11 PM
  2. Fantasy Football Offline Draft Manager Program
    By aussiemcgr in forum Java Theory & Questions
    Replies: 0
    Last Post: September 6th, 2010, 09:52 AM
  3. My Custom Layout (VERY EASY TO USE)
    By aussiemcgr in forum AWT / Java Swing
    Replies: 10
    Last Post: August 5th, 2010, 01:37 PM
  4. How do you layout these components centered
    By robertbob in forum AWT / Java Swing
    Replies: 2
    Last Post: May 24th, 2010, 11:52 PM
  5. Senior Development Manager - Core Java/J2SE - £80-90K + £10K Bonus
    By iNeedJavaGurus in forum Paid Java Projects
    Replies: 0
    Last Post: September 18th, 2009, 10:00 AM