Results 1 to 10 of 10
  1. #1
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default PlaygroundPanel + ButtonPanel

    Hello,

    I have drawn a PlaygroundPanel. This is one class.
    I hava a button Panel. This is one class.
    In a handler i start a frame and the PlaygroundPanel is working fine.

    But i want a frame with the PlaygroundPanel and the ButtonPanel.

    Playground on the left, buttons on the right. The buttons vertical beneath eachother.

    What have i done so far.
    1. tested GridLayout, it shows 50 % of my panel, but it shows the buttons.
    2. When add the button panel i lose keyboard control in my drawn panel.

    3. I have used borderLayout but i cannot control the bounds of a button.

    So what is the best option to do this?


    Thanks for your help.


    Kind regards,

    André

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    How did you add the buttons to a button panel? You can probably use a vertical box for the button panels layout manager.

    You can also check out gridbaglayout for more control, or nesting layout managers to get the control you want. I'm not entirely sure what you want the program to look like, would you mind posting a sketch of what it supposed to look like? Can you also give a more detailed explanation of the problems you are having?

  3. #3
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Hi Sunde,

    Thanks for the reply.
    I got it to work in the following code:

    Java Code:
                ButtonPanel panelEast = new ButtonPanel();
                panelEast.setLayout(new GridLayout(4, 4));
                panelEast.setFocusable(true);
    
                KeyPanel panelCenter = new KeyPanel(spel.getPlayground(), 30, 30, 20, 20);
                panelCenter.setLayout(new GridLayout(3, 3));
                panelCenter.setFocusable(true);
    
                JPanel parent = new JPanel();
                parent.setLayout(new BorderLayout());
                parent.add(panelEast, BorderLayout.EAST);
                parent.add(panelCenter, BorderLayout.CENTER);
               
    
                //  bouw het frame waarin het spel moet draaien op
                JFrame frame = new JFrame("Spel: Sokoban - Level: " + spel.level.getNaam() + " - Speelveld: " + spel.playground.getNaam() + " - Speler: " + spel.getPlayernaam());
                frame.setSize(900, 800);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
                frame.add(parent);
    See the attachtment for what i want.

    Kind regards,

    André
    Attached Thumbnails Attached Thumbnails PlaygroundPanel +  ButtonPanel-result.jpg  

  4. #4
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    I have played a bit with the vertikal box but you get the strange width of a button.
    Can i do anything about that.
    And i got one button who's wdth was over the whole page, i'm not sure of doing it right.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    A vertical box and a change of the buttons size may work, the center frame may expand, not sure if that's fine or not. Try using setPreferredSize and seeing if that changes anything.

  6. #6
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Hi Sunde,

    This worked, but you need to set the Minimum and maximum size to of each button and then add them to the vertical Box.

    stopButton.setMinimumSize(buttonSize);
    stopButton.setPreferredSize(buttonSize);
    stopButton.setMaximumSize(buttonSize);

    One question remains, there is no space between the buttons.
    Solution: make 3 vertikal boxes, but then there is to much space.
    I have tried the size/bounds methods on a vertical box but i can't seem to make it smaller.

    Are there any other solutions, to get space between the buttons?

    Kind regards,

    André

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are looking to increase vertical spacing?

  8. #8
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    thats correct

  9. #9
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Check out Box.createRigidArea method.

  10. #10
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

Posting Permissions

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