aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem on JPanel.setBackGround Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem on JPanel.setBackGround" Watch "Problem on JPanel.setBackGround" New topic
Author

Problem on JPanel.setBackGround

huang gang
Greenhorn

Joined: Nov 17, 2002
Posts: 13
Hi all, I meet another problem,

Why does my code does not work? Listed as follows:

//////////////////////////////////////////////////
JPanel pane1 = new JPanel();
...//some setting here
JPanel pane2 = new JPanel();
...//somesetting here
pane2.setBackGround(Color.white);

JScrollPanel jsp = new JSCorllPanel(pane2, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, pane1, pane2);

this.getContentPane().add(split);
this.setVisible();

split.setDividerLocation(0.25);
//////////////////////////////////////////////////

why does the enbolded line not work? The background of pane2 is still gray.

can anybody help? thanks!
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Spelling it this way pane2.setBackGround(Color.white); brings this compile–time exception:

huang gang
Greenhorn

Joined: Nov 17, 2002
Posts: 13
thanks for concern...

I am not copy code from source, so sorry for the mistake.
you code does work, but mine does not.

the pane2 is an instanse of a new component extends JPanel, I think the problem must be there. I must have miss something.
[ May 30, 2004: Message edited by: huang gang ]
parvez ali
Greenhorn

Joined: Oct 08, 2010
Posts: 7
though you haven't given the code for the class which extended JPanel, i am pretty sure you haven't called

super.paintComponent(); in the paintComponent() method of the extending class.
you see in swing you dont override the paint() method, but the paintComponent(),paintBorder() and
paintChildren() methods.
Check it out as i was facing the same problem.
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
parvez ali wrote:though you haven't given the code for the class which extended JPanel, i am pretty sure you haven't called

super.paintComponent(); in the constructor of the extending class.
Check it out as i was facing the same problem.


Assuming that the OP posted code that is similar to his actual problem, this wouldn't be the case because he's not extending JPanel.

But OP, you need to post a small piece of runnable code that demonstrates the problem if you want help.
parvez ali
Greenhorn

Joined: Oct 08, 2010
Posts: 7
very sorry for my carelessness.
thanks Kevin for pointing out my mistake.
Actually i am facing the same problem, can somebody help me out
...
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
parvez ali wrote:very sorry for my carelessness.
thanks Kevin for pointing out my mistake.
Actually i am facing the same problem, can somebody help me out...

I think that you'll want to ask your own question in its own thread and link to this one rather than hijack someone else's thread.

Best of luck.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Parvez ,
I have edited out your post.
You can create a new thread, using the button at the top of this page.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem on JPanel.setBackGround