各位达人:
您好!目前我用swing做界面,当按钮选中焦点的时候,焦点的显示非常不明显。目前我用的方法是在CSDN上的方法:
自己写一个:MyButtonUI
package ui;import javax.swing.AbstractButton;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalButtonUI; import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle; public class MyButtonUI extends MetalButtonUI{ int rectGapX;
int rectGapY;
int rectGapW;
int rectGapH; public MyButtonUI() {
rectGapX = UIManager.getInt( "ButtonUI.dashedRectGapX ");
rectGapY = UIManager.getInt( "ButtonUI.dashedRectGapY ");
rectGapW = UIManager.getInt( "ButtonUI.dashedRectGapWidth ");
rectGapH = UIManager.getInt( "ButtonUI.dashedRectGapHeight ");
} protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect,
Rectangle textRect, Rectangle iconRect) { textRect = new Rectangle(rectGapX+3, rectGapY+3, b.getWidth()-rectGapW-6,
b.getHeight()-rectGapH-6);
super.paintFocus(g, b, viewRect, textRect, iconRect);
}
}
然后:
JButton button = new JButton( "test Button ");
MyButtonUI bui = new MyButtonUI();
button.setUI(bui);这样的方法,可以将:焦点的边框 和 按钮的边框的距离近一些!
但小弟请教:
1,是否可以将 焦点的边框 加粗
2,是否可以将 焦点的边框 变色
反正:目的只有一个,就是将焦点搞得醒目一些,让用户能够一眼看清楚~!!
大人们看是否能在上面的 MyButtonUI 上改写,或者 用其他方法来 设置button的属性!
谢谢了!
您好!目前我用swing做界面,当按钮选中焦点的时候,焦点的显示非常不明显。目前我用的方法是在CSDN上的方法:
自己写一个:MyButtonUI
package ui;import javax.swing.AbstractButton;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalButtonUI; import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle; public class MyButtonUI extends MetalButtonUI{ int rectGapX;
int rectGapY;
int rectGapW;
int rectGapH; public MyButtonUI() {
rectGapX = UIManager.getInt( "ButtonUI.dashedRectGapX ");
rectGapY = UIManager.getInt( "ButtonUI.dashedRectGapY ");
rectGapW = UIManager.getInt( "ButtonUI.dashedRectGapWidth ");
rectGapH = UIManager.getInt( "ButtonUI.dashedRectGapHeight ");
} protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect,
Rectangle textRect, Rectangle iconRect) { textRect = new Rectangle(rectGapX+3, rectGapY+3, b.getWidth()-rectGapW-6,
b.getHeight()-rectGapH-6);
super.paintFocus(g, b, viewRect, textRect, iconRect);
}
}
然后:
JButton button = new JButton( "test Button ");
MyButtonUI bui = new MyButtonUI();
button.setUI(bui);这样的方法,可以将:焦点的边框 和 按钮的边框的距离近一些!
但小弟请教:
1,是否可以将 焦点的边框 加粗
2,是否可以将 焦点的边框 变色
反正:目的只有一个,就是将焦点搞得醒目一些,让用户能够一眼看清楚~!!
大人们看是否能在上面的 MyButtonUI 上改写,或者 用其他方法来 设置button的属性!
谢谢了!
你选中焦点public void mouseMoved(MouseEvent e) {}
有个setColor()方法改变颜色的。具体的写法要看你按项目了。
或者用SYNTH自定义风格也可以啦
你选中焦点public void mouseMoved(MouseEvent e) {} 这个动作加上去后!
如何设置焦点?
是用button的属性设置
还是什么?