Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2005

Tip: Looking for answers? Try searching our database.

problem using html for multiline jbutton

Thread view: 
anikkar@gmail.com - 27 Oct 2005 19:26 GMT
I am using html to create a multiline JButton, which works fine, but
when i disable the jbutton, the text is still the same color (it is not
faded), however, the Jbutton does become disabled.

anyone else run into this problem?
anikkar@gmail.com - 27 Oct 2005 21:24 GMT
apparently, this is a known bug

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4783068
Andrey Kuznetsov - 27 Oct 2005 23:32 GMT
> apparently, this is a known bug
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4783068

yes, did you read also about workaround there?

I suggest however to use a slightly another solution:

public class HtmlButton2 extends JButton {
   private String html = "<html>";
   private String disabledColor = "<font color=\"gray\">";

   String enabledText;
   String disabledText;
   boolean isHtml;

   public HtmlButton2() {
       super();
   }

   public HtmlButton2(String text) {
       super(text);
   }

   public void setText(String text) {
       if (text.startsWith(html)) {
           isHtml = true;
           enabledText = text;
           text = text.substring(html.length());
           disabledText = html + disabledColor + text;

           if (isEnabled()) {
               setTextImpl(enabledText);
           }
           else {
               setTextImpl(disabledText);
           }
       }
       else {
           isHtml = false;
           enabledText = text;
           disabledText = text;
           setTextImpl(enabledText);
       }
   }

   protected void setTextImpl(String text) {
       super.setText(text);
   }

   public void setEnabled(boolean b) {
       if (isHtml) {
           if (b) {
               setTextImpl(enabledText);
           }
           else {
               setTextImpl(disabledText);
           }
       }
       super.setEnabled(b);
   }
}

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

anikkar@gmail.com - 27 Oct 2005 23:40 GMT
thanks...i'll give it a try
anikkar@gmail.com - 31 Oct 2005 22:58 GMT
Hi Andrey,

I tried this, and I got a problem at first, and found that you needed
to set the html and disabled fields as static, and then everything
works out. Thanks!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.