Results 1 to 10 of 10
Thread: PlaygroundPanel + ButtonPanel
- 03-26-2011, 07:28 AM #1
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
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é
- 03-26-2011, 07:53 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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?
- 03-26-2011, 08:14 AM #3
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Hi Sunde,
Thanks for the reply.
I got it to work in the following code:
See the attachtment for what i want.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);
Kind regards,
André
- 03-26-2011, 08:17 AM #4
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
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.
- 03-26-2011, 08:33 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 03-26-2011, 09:53 AM #6
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
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é
- 03-26-2011, 10:00 AM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You are looking to increase vertical spacing?
- 03-26-2011, 10:01 AM #8
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
thats correct
- 03-26-2011, 10:15 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Check out Box.createRigidArea method.
- 03-26-2011, 07:36 PM #10
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks