File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JComponent text in some JApplets don't show on Mac, do show on Windows PC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComponent text in some JApplets don Watch "JComponent text in some JApplets don New topic
Author

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

Samuel Baker
Greenhorn

Joined: Sep 05, 2011
Posts: 4
[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

Joined: Jun 13, 2009
Posts: 2227
    
    8
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

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

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Samuel Baker
Greenhorn

Joined: Sep 05, 2011
Posts: 4
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

Joined: May 03, 2008
Posts: 4664
    
    5

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)


luck, db
There are no new questions, but there may be new answers.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
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

Joined: Sep 05, 2011
Posts: 4
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

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

Joined: Sep 05, 2011
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JComponent text in some JApplets don't show on Mac, do show on Windows PC