protected String paramString() {
String str;
if (linkBehavior == ALWAYS_UNDERLINE)
str = "ALWAYS_UNDERLINE";
else if (linkBehavior == HOVER_UNDERLINE)
str = "HOVER_UNDERLINE";
else if (linkBehavior == NEVER_UNDERLINE)
str = "NEVER_UNDERLINE";
else
str = "SYSTEM_DEFAULT";
String colorStr = linkColor == null ? "" : linkColor.toString();
String colorPressStr = colorPressed == null ? "" : colorPressed
.toString();
String disabledLinkColorStr = disabledLinkColor == null ? ""
: disabledLinkColor.toString();
String visitedLinkColorStr = visitedLinkColor == null ? ""
: visitedLinkColor.toString();
String buttonURLStr = buttonURL == null ? "" : buttonURL.toString();
String isLinkVisitedStr = isLinkVisited ? "true" : "false";
return super.paramString() + ",linkBehavior=" + str + ",linkURL="
+ buttonURLStr + ",linkColor=" + colorStr + ",activeLinkColor="
+ colorPressStr + ",disabledLinkColor=" + disabledLinkColorStr
+ ",visitedLinkColor=" + visitedLinkColorStr
+ ",linkvisitedString=" + isLinkVisitedStr;
}
}
class BasicLinkButtonUI extends MetalButtonUI {
private static final BasicLinkButtonUI ui = new BasicLinkButtonUI();
public BasicLinkButtonUI() {
}
public static ComponentUI createUI(JComponent jcomponent) {
return ui;
}
protected void paintText(Graphics g, JComponent com, Rectangle rect,
String s) {
LayoutDemo bn = (LayoutDemo) com;
ButtonModel bnModel = bn.getModel();
Color color = bn.getForeground();
Object obj = null;
if (bnModel.isEnabled()) {
if (bnModel.isPressed())
bn.setForeground(bn.getActiveLinkColor());
else if (bn.isLinkVisited())
bn.setForeground(bn.getVisitedLinkColor());
else
bn.setForeground(bn.getLinkColor());
} else {
if (bn.getDisabledLinkColor() != null)
bn.setForeground(bn.getDisabledLinkColor());
}
super.paintText(g, com, rect, s);
int behaviour = bn.getLinkBehavior();
boolean drawLine = false;
if (behaviour == LayoutDemo.HOVER_UNDERLINE) {
if (bnModel.isRollover())
drawLine = true;
} else if (behaviour == LayoutDemo.ALWAYS_UNDERLINE || behaviour == LayoutDemo.SYSTEM_DEFAULT)
drawLine = true;
if (!drawLine)
return;
FontMetrics fm = g.getFontMetrics();
int x = rect.x + getTextShiftOffset();
int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1;
if (bnModel.isEnabled()) {
g.setColor(bn.getForeground());
g.drawLine(x, y, (x + rect.width) - 1, y);
} else {
g.setColor(bn.getBackground().brighter());
g.drawLine(x, y, (x + rect.width) - 1, y);
}
}
}
----------------------------
Visit for more information:
http://www.roseindia.net/java/example/java/swing/Thanks.