• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem on JPanel.setBackGround

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
...
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic