Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Button Colors Different in XP and Win 8

 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program I wrote long ago. I change colors of buttons at times. Here is the code:



The color of the buttons has always changed under XP but when I run the program on Windows 8 only the edges of the bottons change
ButtonColors on XP.jpg
[Thumbnail for ButtonColors on XP.jpg]
Buttons when on XP
ButtonColorsWin8.jpg
[Thumbnail for ButtonColorsWin8.jpg]
Buttons when on Windows 8
 
Campbell Ritchie
Marshal
Posts: 53110
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I shall move this discussion to our GUIs forum. Not sure, but what look'n'feel are you using?
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell,

(1) Thanks for the welcome,

(2) Thanks for moving to the correct place.

(3) I never heard of Look and Feel so I am researching it starting now.

Thanks Again,

Pete
 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This tutorial might be a good thing to read.

Look and feel (or "LAF") is subtler than it seems, at first. Even though every LAF will let you set some of the same properties of your on-screen objects as every other LAF, some LAFs so thoroughly take control of those objects' appearances that your settings don't make any visible difference. It can be frustrating, but it often takes no more than choosing a different LAF to get the result you wanted.
 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, welcome to the Ranch.

I took the liberty of reformatting your code using code tags, and adjusting your indentation/spacing/whitespace a bit. Makes things easier to read.

I see you are an adherent of K&R style indentation. I like Allman style myself, but I believe every coder's entitled to follow their own muse on indentation (so long as they do so with an iron discipline of consistency ). However, I do think you should change your "Player" variable's capitalization: Java variables conventionally start with a lower-case letter.
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what code tags are. I also didn't do anything about indentation. I just used Netbeans and took whatever it gave me. I admit I really don't know what I am doing. (Check my bio).

We have this card game the family plays when we get together. The scoring is pretty complex and can get confusing when we have "had a few". A while back I wrote some Excel macros to help keep score. Then 9 months ago I decided I needed to create a stand alone, cross platform version. Also, it was time for me to get into OOP. Java looked like a good place to start. And after many miscues, tangents, screw-up's and everything else, I had a working version except for this difference.

I have been reviewing the LAF tutorial. Lots to learn before I understand it. But I looked at other sites and tried some experiments and my gut feeling is LAF isn't causing this. But I will admit I am more likely to be wrong then right.

Pete
 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Calinski wrote:I don't know what code tags are.


UseCodeTags will tell you all about them.
 
Campbell Ritchie
Marshal
Posts: 53110
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NetBeans defaults to K&R indentation.
 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:NetBeans defaults to K&R indentation.

Yeah, it comes configured that way. It's trivial to set it to Allman, though some of its templates require reformatting if you want it to apply everywhere.
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you dudes realize how, for a newbie, this is like drinking from a fire hose?

Thanks for your being patient.

Still researching LAF.
 
Tony Docherty
Saloon Keeper
Posts: 3154
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Calinski wrote:Do you dudes realize how, for a newbie, this is like drinking from a fire hose?

Yes, we were all newbies once and in fact we are all still newbies with regard to each new Java feature/framework/technology that comes along with seemingly alarming regularity.

If you want full control of colouring button backgrounds etc one of the L&F's that does allow this is the Windows Classic L&F. You can set it by including the following line in your program before creating any GUI components.
 
Campbell Ritchie
Marshal
Posts: 53110
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Calinski wrote:Do you dudes realize how, for a newbie, this is like drinking from a fire hose? . . .
This is us having our own drink and you watching from the other side of the bar
Sorry.
 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Calinski wrote:Do you dudes realize how, for a newbie, this is like drinking from a fire hose?


Fair point. We kind of drifted off your topic, which happens more than it probably should here.

Try adding this to your main routine:


At Line 3, I'm setting my LAF to "Windows Classic," which gives me the all-green button background you want. If I set it to "Windows" (which is probably what your system is defaulting to), I get the mostly gray, green boundary you're seeing.

(Sorry if the line numbers aren't correctly aligned with the source code; this is a known problem here, and Powerful Minds are looking into it.)
ButtonsWindowsClassic.jpg
[Thumbnail for ButtonsWindowsClassic.jpg]
With the Windows Classic LAF.
ButtonsWindows.jpg
[Thumbnail for ButtonsWindows.jpg]
With the Windows LAF.
 
Pete Calinski
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, once I knew where to look, looky what I found:
So I commented that out and pasted Stevens code in place and it worked.

You guys nailed it!

Thanks,

Pete

 
Stevens Miller
Bartender
Posts: 1422
29
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done, Pete! All you really needed to do was change "Nimbus" (which is poo, imho ), to "Windows Classic" (which is the only LAF that never screws fails me in Windows ) at Line 8.

Glad you got it working.
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, netbeans was "helping me". Just what a guy needs.


Sorry for the delayed response but I hit another bug and after a few hours of trying I'll post my problem under a new thread.

Thanks again,

Pete

 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!