Results 1 to 8 of 8
Thread: I need some help with JPanel
- 11-03-2009, 01:54 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
I need some help with JPanel
hello. I have a JFrame, I use a container for this. Now, i want to add two JPanels to the container and then add the container to the JFrame. My problem is that I cannot set the "size" of the JPanels. I want the first Jpanel to take the 1/3 of the screen vertical, and the other JPanel to take the rest of the Jframe. How can I do that? panel.setSize and setPreferedSize does not work .
Do you have any suggestions?, because i really need it.
thank you
- 11-03-2009, 01:59 PM #2
Which LayoutManager do you use?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-03-2009, 02:06 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
when i try to use the setsize and setpreferedsize i use borderlayout manager. I think that GridLayout is more flexible, but when i try to use it i get an exception error. I think that I am looking for a nice tutorial or a good code example on GridLayout. Here is my GridLayout code, which does not do the work and throws exception.
static JPanel p = new JPanel( ) ;
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 10;
c.gridheight = 10;
c.weightx = 30;
c.weighty = 30;
c.fill = GridBagConstraints.NONE;
p.setLayout(new GridBagLayout());
contentPane.add(p,c );
- 11-03-2009, 02:07 PM #4
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
Here is the Exception
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null)
thanks for your interest mr. phHein
- 11-03-2009, 02:08 PM #5
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-03-2009, 04:37 PM #6
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 284
- Rep Power
- 4
In your code, the line "contentPane.add(p,c);" will cause the exception.
The second argument to add() must be a string name.
The layout manager will use this name to choose where to put the object in its layout.
GridBagLayout does not use this name. For GridBagLayout, the call is:
You might consider using JSplitPane: How to Use Split Panes. Then there's no need for a layout manager.Java Code:gridbag.setConstraints(button, c); add(button);
- 11-03-2009, 05:09 PM #7
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Use a vertical BoxLayout and set the preferred size of each component.
- 11-03-2009, 07:58 PM #8
Member
- Join Date
- Nov 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
.add to a JPanel
By harrier in forum NetBeansReplies: 11Last Post: 07-13-2010, 10:24 AM -
how to set image to a jpanel
By masa in forum AWT / SwingReplies: 1Last Post: 03-02-2009, 08:36 AM -
How to use Jpanel
By Manfizy in forum NetBeansReplies: 0Last Post: 02-19-2009, 12:34 PM -
refresh JPanel
By olesja in forum AWT / SwingReplies: 1Last Post: 04-16-2008, 03:58 PM -
Problem with JPanel
By ibanez270dx in forum New To JavaReplies: 2Last Post: 11-09-2007, 05:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks