• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem on JPanel.setBackGround

 
huang gang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spelling it this way pane2.setBackGround(Color.white); brings this compile–time exception:

 
huang gang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parvez ,
I have edited out your post.
You can create a new thread, using the button at the top of this page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic