The Artima Developer Community
Sponsored Link

Java Answers Forum
Background colour in swing and textbox set focus

4 replies on 1 page. Most recent reply: Nov 28, 2003 12:01 PM by Paul Rogers

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
steps

Posts: 14
Nickname: spanishste
Registered: Nov, 2003

Background colour in swing and textbox set focus Posted: Nov 25, 2003 3:13 AM
Reply to this message Reply
Advertisement
Hello everybody,

1.How can i change the background colour of my GUI(swing).I want the default colour gray to be changed.
I'm able to change the background colour for a panel but not on the whole screen.

2.How can i restrict the textbox to 3 characters and when all the 3 are entered it has to set focus to the next one.(For ex,in the case of Ip-address).

Thanks in advance


Ernie Douglas

Posts: 18
Nickname: y2j
Registered: Nov, 2002

Re: Background colour in swing and textbox set focus Posted: Nov 25, 2003 7:13 AM
Reply to this message Reply
go to this site
http://search.java.sun.com/search/java/?qt=background+colour

it will show you examples of coding for backgrounds and changing colours

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Background colour in swing and textbox set focus Posted: Nov 27, 2003 3:49 PM
Reply to this message Reply
setBackground
public void setBackground(Color bg)Sets the background color of this component.

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Background colour in swing and textbox set focus Posted: Nov 27, 2003 3:53 PM
Reply to this message Reply
Oops on the second part, add a KeyListener to the first JTextComponent which checks to see if the entry is complete, and have the
call the requestFocus method on the next JTextComponent

Paul Rogers

Posts: 1
Nickname: wcpr
Registered: Apr, 2003

Re: Background colour in swing and textbox set focus Posted: Nov 28, 2003 12:01 PM
Reply to this message Reply
Although you can use java.awt.Component.setBackground(Color) as previously noted, if you need to do so on all Compnonents in the app (for consistency) investigate changing the Swing system colors (which you'll only have to do once (DRY)):

http://home.tiscali.nl/~bmc88/java/sbook/061.html

-wcpr-

Flat View: This topic has 4 replies on 1 page
Topic: dft in java Previous Topic   Next Topic Topic: re: source code

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use