473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

add conponents to panel

2
how to add components to the panel on the fly
following code is not work
JButton b=new JButton("hjkhk");
jPanel3.add(b);
setContentPane(jPanel3);

I hope your help
Oct 12 '07 #1
3 1263
r035198x
13,262 8TB
how to add components to the panel on the fly
following code is not work
JButton b=new JButton("hjkhk");
jPanel3.add(b);
setContentPane(jPanel3);

I hope your help
Don't set the contentPane to be the panel. Instead use
Expand|Select|Wrap|Line Numbers
  1. getContentPane().add(jPanel3);
Oct 12 '07 #2
JosAH
11,448 Expert 8TB
Don't set the contentPane to be the panel. Instead use
Expand|Select|Wrap|Line Numbers
  1. getContentPane().add(jPanel3);
As a matter of fact setting the content pane to a JPanel does work. All the JFrame
wants is that its content pane should be a JComponent and it must be opaque.

The JFrame's add() method delegates to its content pane's add() method and all
JComponents have such a method (inherited from the Container class), so there's
no problem here.

You could wonder why to create a JPanel in the first place because the original
content pane is a JComponent and thus a Container (with a BorderLayout) so it
can do the job as well.

kind regards,

Jos
Oct 12 '07 #3
r035198x
13,262 8TB
As a matter of fact setting the content pane to a JPanel does work. All the JFrame
wants is that its content pane should be a JComponent and it must be opaque.

The JFrame's add() method delegates to its content pane's add() method and all
JComponents have such a method (inherited from the Container class), so there's
no problem here.

You could wonder why to create a JPanel in the first place because the original
content pane is a JComponent and thus a Container (with a BorderLayout) so it
can do the job as well.

kind regards,

Jos
I just thought they may want other panels to appear together with that panel (judging from the variable names they have).
The setContentPane is certainly not the reason why their code "is not work".
Oct 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Fabrizio | last post by:
Hi, There is any chance to insert a control like a text box in a panel choosing the absolute position? When I try to insert a label , the panel positions the control on a locked position. Thanks...
9
by: Bill Long | last post by:
I have a control that simply displays a list of links. Following one of the links doesn't post back or redirect to another page, it simply hides the current panel and shows the one you selected......
2
by: Peteroid | last post by:
When the application I'm working on is run it creates a panel with a Paint event customized to draw primitives (circles, rectangles, etc.), places the panel on a form, and then launches the form....
1
by: clintonG | last post by:
I'm having a problem maintaining state with a Panel control in a MasterPage and I need help thinking through this process. The basic structure of the HTML in the Master looks like this... ...
3
by: John Salerno | last post by:
I'm using the sample code of the file 'simple.py' and trying to make a single window with a panel in it, but I keep getting an error. Here's my code: (I know I might need something else, like a...
10
by: markwalker84 | last post by:
Hello everyone! Got a bit of a problem... Two of the panels on my program contain a number of check boxes. The exact number of which is determined by a pair of variables. I have recently...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
11
by: dongarbage | last post by:
Hi there, I'm very much a C# novice. How do you do freehand drawing on a panel with a mouse in c#? Thanks, Don
3
by: Gandalf | last post by:
why when I try to insert gridSizer to a panel which already inside another panel the gridSizer doesn't work? this is the code: panel3= wx.Panel(self, -1, (0, 60), size=(400, 240) ,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.