Closed Thread
Results 1 to 8 of 8

Thread: Swing

  1. #1
    R3.RyozKidz Guest

    Swing

    how many layout manager can i use in a single JPanel ..?

  2. CODECALL Circuit advertisement

     
  3. #2
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Swing

    One.
    Wow I changed my sig!

  4. #3
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,879
    Rep Power
    24

    Re: Swing

    One.
    Haha, one of the shortest answers around here

    It's indeed 1, if you want another one, you must put a JPanel in a JPanel where both have the layout you want.

  5. #4
    R3.RyozKidz Guest

    Re: Swing

    if(provided_answer == shortest_answer)
    {
    easy to understand ;
    }
    else
    {
    head bursting;
    haha;
    }


    what do u mean by putting a JPanel inside a JPanel ..?
    using add method in JPanel to include another JPanel..?

  6. #5
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,879
    Rep Power
    24

    Re: Swing

    Yes if you would like a gridlayout in the SOUTH of a borderlayout for example you have no other choice than using 2 JPanels:

    [highlight=Java]
    JPanel borderPanel;
    JPanel gridPanel;

    borderPanel = new JPanel();
    gridPanel = new JPanel();

    borderPanel.setLayout(new BorderLayout());
    gridPanel.setLayout(new GridLayout(x,y));

    borderPanel.add(gridPanel, BorderLayout.SOUTH);
    [/highlight]

    where x and y are numbers. Only 1 of them may be a number above 0, the other one must be set to 0 (zero)
    You can make it shorter by doing:
    [highlight=Java]
    borderPanel = new JPanel(new BorderLayout());
    [/highlight]

  7. #6
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Swing

    @oxano: Why not combine the declaration and the definition of the JPanel objects and use the Layout Manager constructor?
    Code:
    JPanel borderPanel = new JPanel(new BorderLayout());
    JPanel gridPanel = new JPanel(new GridLayout(x, y));
    Wow I changed my sig!

  8. #7
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,879
    Rep Power
    24

    Re: Swing

    To make it clear. I did mention that you can do it shorter by doing so at the end of my post.

  9. #8
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Swing

    I was more referring to combining the declaration and constructor into one statement, I did notice what you said.

    But yeah, making sure it's clearer is a good objective, I 'spose. Just wanted to make sure that if you use it in production code you do it the short, easier way.
    Wow I changed my sig!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. GUI help - awt or swing or both?
    By An Alien in forum Java Help
    Replies: 4
    Last Post: 10-29-2011, 12:29 PM
  2. SWT vs. Swing - Debate?
    By gregwarner in forum The Lounge
    Replies: 3
    Last Post: 04-02-2011, 10:24 AM
  3. Help with java swing please!
    By boburob in forum Java Help
    Replies: 4
    Last Post: 01-01-2009, 12:52 PM
  4. Help with swing !
    By Turk4n in forum Java Help
    Replies: 7
    Last Post: 09-26-2008, 02:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

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