Results 1 to 11 of 11
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default boxlayout as a prelude for the gridbag

    I thought: one begins with an empty JPanel
    and fill it with some stuff using a box layout
    and return the filled JPanel.....

    But what a mess I got instead!
    1) is the concept of the method alright (filling an empty panel)?
    2) why is everything cluttered on the panel (I believe I followed
    the instructions of the box layout? What is going wrong here?
    Thanks for any comment.

    Java Code:
     public JPanel CreateSingleRoomPanel(JPanel jp)   {
            
            firstname = new JLabel("firstname");
            lastname = new JLabel("lastname");
            endtime = new JLabel("00.00");
            reserved = new JLabel("REREVED");
    
            TimeBar = new JProgressBar(0, 60);
            TimeBar.setPreferredSize( new Dimension( 5, 30 ) );
            TimeBar.setStringPainted(false);
            TimeBar.setValue(0);
            TimeBar.setOrientation(SwingConstants.VERTICAL);
            TimeBar.setStringPainted(true);
            
            bh1 = Box.createHorizontalBox();
            bh2 = Box.createHorizontalBox();
            bh3 = Box.createHorizontalBox();
            bv1 = Box.createVerticalBox();
            bv2 = Box.createVerticalBox();
    
            bh1.add(firstname);
            bh1.add(Box.createGlue());
            bh1.add(TimeBar);
    
            bh2.add(lastname);
            bh2.add(Box.createGlue());
    
            bh3.add(reserved);
            bh2.add(Box.createGlue());
            bh3.add(endtime);
    
            bv1.add(bh1);
            bv1.add(bh2);
            bv1.add(Box.createGlue());
            bv1.add(bh3);
            jp.add(bv1);
    
            return jp;
    
        }

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    Of course the method is a model and values will be set after
    (would that be a problem concerning references.....)

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: boxlayout as a prelude for the gridbag

    Where do you set the LayoutManager for jp?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    so that is the problem should add something like this
    jp.setLayout(new BoxLayout(jp, BoxLayout.PAGE_AXIS));
    right PhHein?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: boxlayout as a prelude for the gridbag

    Once you have given the panel a layout manager (without which it defaults to, I think, flow), I spotted this:
    Java Code:
    bh3.add(reserved);
    bh2.add(Box.createGlue());
    bh3.add(endtime);
    I think that middle one should be 'bh3', not 'bh2'?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    Yes I saw it too and is already corrected, thanks anyway
    The panel looks better but there are still some issues left
    I'll keep on studying and I'll come back if I have any questions?

    thanks Tolls

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    How to layout a component beginning from the left upper corner?

  8. #8
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    So the single panel method is part of the next method.
    Would I have any problem when setting the different labels?
    I mean the 100 panels have their references stored into a array.
    So I may say: roominfo[4].getRoomPanel().firstname.setText("what ever")?
    When the arrays has the reference of the fourth panel.
    Or Am I to optimistic here?

    Java Code:
     public JPanel CreatePanels() {
    
            int arraycount= 0;          // panel CENTER
            roomPanel = new JPanel();
            roomPanel.setLayout(new GridLayout(10,10));
            JPanel rp;
            for (int i = 3; i <6; i++) {
                for (int ii = 0; ii <=29; ii++) {
                    int room = (i*100)+ii;
                    rp = new JPanel();
                    rp = RoomP.CreateSingleRoomPanel(rp);
    
                    // design of the panel
                    roomPanel.add(rp);
                    etched = BorderFactory.createEtchedBorder();
                    titled = BorderFactory.createTitledBorder(etched, 
                            "ROOM " + room);
                    rp.setBorder(titled);
    
                    roominfo[arraycount].setRoomNumber(room);
                    roominfo[arraycount].setRoomPanel(rp);
    
                    if (roominfo[arraycount].getPiano());
    
                    arraycount++;
                }
            }  
            return roomPanel;
        }

  9. #9
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    No i obviously can not do that!

  10. #10
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    So I create 100 JPanels and story each reference into array of objects: roominfo[].setRoomPanel() of type JPanel.
    Next I put a bunch of JLabels on each panel and want to changes its texts, right!
    How am I going to do that?
    (So I might need a reference of each JLabel (5 labels per panel: so 5*100)

  11. #11
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: boxlayout as a prelude for the gridbag

    A two-dimensional array [1-100] [1-5]?

Similar Threads

  1. Gridbag layout
    By ramesh.8189 in forum AWT / Swing
    Replies: 5
    Last Post: 02-23-2009, 11:31 PM
  2. Gridbag layout
    By ramesh.8189 in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 06:21 PM
  3. include-prelude/include-coda
    By devin in forum Java Servlet
    Replies: 0
    Last Post: 02-11-2009, 07:33 PM
  4. Require Help with Layout (GridBag)
    By hemanthjava in forum AWT / Swing
    Replies: 2
    Last Post: 10-22-2008, 01:56 PM
  5. Gridbag Layout Probelm
    By hemanthjava in forum AWT / Swing
    Replies: 3
    Last Post: 12-04-2007, 05:12 PM

Posting Permissions

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