java按钮点击处于当前焦点的时候,能否边框线不在文字边沿,而是在按钮边沿呢?就像windows的按钮那样,焦点时的边框线都是在按钮边沿的。
解决方案 »
- 类的初始化的问题 求指教!
- 编写一个程序,求2—200之间的素数,并将结果保存在文件prime.dat中。再从该文件中读取内容并在屏幕上显示出来。
- 一个非常奇怪的jni调用的问题
- 新手做日历时的一个问题
- 如何让线程能在固定的时间运行?(也就是不管我在任何时间启动线程)
- 超级菜鸟问题,FileInputStream为什么找不到跟class文件放在同一目录下的文件
- 请大家帮个忙,非常感谢!!!
- java写了一个爬虫,出现Software caused connection abort: recv failed 异常
- 找不到工作郁闷。
- 高手請指教,高分相送!!!
- 麻烦大家帮我看看这个程序,感谢了!
- java 特别基础的问题(急)
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalButtonUI;
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);
Insets inset = new Insets(1,1,1,1); //这个数值就是那个边框线离四个边框的距离
button.setMargin(inset); OK了