Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JColor Chooser - JLabels?

 
Jacob Coddaire
Ranch Hand
Posts: 36
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I integrate JColorChooser into each player? I know how to do it for JButtons, but I simply cannot figure out how to do it for JLabels.
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JOptionPane#showXXX methods accept an Object message argument. You can always pass a JColorChooser instance as the message and check for the color chosen by the user

This question is more suitable for the GUI forums.
Moving thread
 
Jacob Coddaire
Ranch Hand
Posts: 36
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That literally does not make any sense to me.
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jacob Coddaire
Ranch Hand
Posts: 36
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I've almost got it. Here's the code so far:


It works, but now I want to apply the color to the JLabels of each. I tried the above code, but it didn't work.
I can't compile it because of setForeground. The error is "The method setForeground(Color) is undefined for the type String."

Any ideas on how to fix this?
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mixing HTML stuff with Swing?

You can set the foreground by
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:

Wouldn't that do the same as
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Wouldn't that do the same as

True.
But
1) Using a JOptionPane for the color chooser would offer the user the same experience as the number of players and name prompt
2) JOptionPane would allow the OP to display custom messages. Something like what color for the player?
3) I had JOptionPane so much in mind that I actually forgot about the JCholorChooser#showDialog()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic