This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
[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.
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
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.
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)
There are no new questions, but there may be new answers.
Joined: Jun 13, 2009
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.
Joined: Sep 05, 2011
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.
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
Joined: Sep 05, 2011
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.