Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComponent text in some JApplets don't show on Mac, do show on Windows PC

 
Samuel Baker
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[If this post is a duplicate, please delete the older one. I'm new here and not sure if I was logged in when I submitted my earlier post.]
If you go to http://sambaker.com/econ/elast/elast.html using a PC, the applets in the page display properly.
If I go there using my Macbook with Lion, the text that goes with the radio buttons in the applets usually doesn't display. I see bare little circles, not little circles with text next to them.
Earlier today, none of the first six applets showed the text that goes with the buttons. On my try right now, with Firefox, 5 of the 6 do show, but one doesn't. In applets further down, some show the text and some don't. Safari shows none of the text.
Is this a known problem with Macs? Is there something I can put in my code to fix this?
Here is the code for one of the applets.



I tried replacing the radio buttons with JButtons. Again, this works fine on my PC, but on my Macbook I see little buttons with no text on them.
I'd appreciate any suggestions you might have for dealing with this.
 
Rob Camick
Ranch Hand
Posts: 2608
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use a Mac but I'm wondering why you use HTML to set the text color of the radio buttons. I would just use the setForeground() method.
 
Maneesh Godbole
Saloon Keeper
Posts: 11090
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just thinking out loud
1) radioButton[i].setFont(new Font(f.getName(),Font.PLAIN,f.getSize())); Try using deriveFont(int style) instead
2) Like Rob suggested, try using setForeground() instead of the html
 
Samuel Baker
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the replies! Using HTML to color the text takes a little less code than putting in setForeground() statements for each button. Your method is cleaner. deriveFont(int style) is a good idea. I wrote these back when Java was version 1.4. As for my main problem, I tried commenting out all of the font statements and got rid of the HTML. My Macbook still didn't show all the applets.
 
Darryl Burke
Bartender
Posts: 5147
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3) Variable (and method) names should start with a lowercase letter. reply, not Reply.
4) A newly constructed JRadioButton is unselected. It's redundant to call setSelected(false)
 
Rob Camick
Ranch Hand
Posts: 2608
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using HTML to color the text takes a little less code than putting in setForeground() statements for each button


That is a terrible reason. Doing stuff like that will cause problems in the long run. The point of writing code is to make is clear and understandable and maintainable. None of us who read the question would understand why you are using HTML in that case. Everybody know how the setForeground() and setBackground() methods work. What ever happens if the user decides they dynamically need to change the text or the color of the text. A change like that would be far more complicated when dealing with HTML, than using either of the setText() or setForeground() methods directly.

And by the way rendering of HTML takes longer and uses more resources than just use straight text.
 
Samuel Baker
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the suggestions for improving my coding style. Making these changes does not solve my problem, which is that I can't rely on Macs to show Swing text.
 
Maneesh Godbole
Saloon Keeper
Posts: 11090
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remember correctly, the jdk installation used to come with samples/demo and one of the demos was the SwingSet, both stand alone as well as applet version. You can try running the applet version on your mac. This might help confirm if it is a mac issue or something else.
I would also suggest running your code but with only one applet at a time. If it works add another applet. Again this might help identify where the problem lies
 
Samuel Baker
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, everybody, for thinking about my problem and making suggestions.
I replaced all the Swing code with AWT. Old and ugly, but it works. Just like me.
I'm leaving it to others to figure out how to make Swing display properly on a Mac.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic