Re: problem using html for multiline jbutton



> 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);
}
}


--
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


.


Quantcast