• 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

Why I can't change the JWindow's color?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone:
I want to use Jwindow to my application. But I find that Jwindow 's background color can't be changed.
my code is:
public static void main(String[] args){JWindow jw=new JWindow();jw.setSize(150,150);jw.setBackground(new Color(23,232,23));jw.setVisible(true);JButton jb=new JButton("Test");jb.setBackground(new Color(23,34,122));jb.setContentAreaFilled(false);//jb.setSize(30,40);jb.setVisible(true);jw.getContentPane().setLayout(new BorderLayout());jw.getContentPane().add(jb);jw.setLocation(1000,800);for(int i=800;i>700;i--){jw.setLocation(1000,i);}
Second, the JButton can't be added to the Jwindow,Why?
Third , When I run the application ,the JWindow will splash one time ,and appear. I don't want it splash when the applicatio starup.How to do it?
Help!
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • JWindows background color can be changed. Set the color on the content pane and not the JWindow reference itself.
  • The JButton *is* being added to the window, but you set the window visible before you add the button. You'll either need to add the button to the window before you cann setVisible() on the JWindow, or you'll need to call validate() on the JWindow after you add the button to the already visible window.
  • I don't understand your third question...

  •  
    Yashnoo lyo
    Ranch Hand
    Posts: 152
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thks.You are right.
    The top question are resolved.
    The third problem's meaning is that:
    I expected my window appear in the right top of my screen.But now ,When I run it ,it splash in the left top,and later appear in the right bottom, why this happen?
    Do you know MSN MEssenger? It have a mail notifier.It will appear when your mailbox have new Email.It appear in the right bottom of your screen,right? I want to do that.
    But my code will appear in the left first,and later appear in the right bottom. I don't know whether I say clearly.
    Can you try my code in your system? Thks:

    Can you try it? If you try it you may find a problem. :roll:
     
    Nathan Pruett
    Bartender
    Posts: 4121
    IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you don't set a location for a window it defaults to the upper left corner of the screen (0,0). You set the location to 1000, 800, this is the lower right corner of the screen (based on your screen size... see next paragraph) You then loop and move the window up the screen. It looks like you are thinking screen coordinates are based off the *lower* left corner of the screen, like normal Cartesian coordinates... nope. The origin (0,0) is in the *upper* left corner of the screen. X coordinates behave the same way, but y coordinates get *larger* as they go down the screen.

    Since you've hard coded the value (1000, 800) as the location of the window, people with different screen sizes may have problems with your code. People who are running at really high resolutions may see the window pop up closer to the middle of their screen, and people that are running at low resolution wouldn't be able to see the window at all... it would pop up off the screen entirely. You can get the screen size by calling Toolkit.getDefaultToolkit().getScreenSize(). You can make calculations off the returned screen size to make sure your code works in all screen resolutions.
    reply
      Bookmark Topic Watch Topic
    • New Topic