网页直播源码,JButton去掉按钮字周围的虚线框

网页直播源码,JButton去掉按钮字周围的虚线框
1.解决办法
使用类 AbstractButton 下的 setFocusPainted 方法,将绘制焦点状态设置为false,则不会在获取到焦点的时候,绘制这个框框了

// 设置 paintFocus 属性,设置为false 则不会绘制焦点状态
button.setFocusPainted(false);

setFocusPainted 方法的源码

/**
     * Sets the <code>paintFocus</code> property, which must
     * be <code>true</code> for the focus state to be painted.
     * The default value for the <code>paintFocus</code> property
     * is <code>true</code>.
     * Some look and feels might not paint focus state;
     * they will ignore this property.
     *
     * @param b if <code>true</code>, the focus state should be painted
     * @see #isFocusPainted
     * @beaninfo
     *        bound: true
     *    attribute: visualUpdate true
     *  description: Whether focus should be painted
     */
    public void setFocusPainted(boolean b) {
        boolean oldValue = paintFocus;
        paintFocus = b;
        firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, oldValue, paintFocus);
        if (b != oldValue && isFocusOwner()) {
            revalidate();
            repaint();
        }
    }

2.代码示例

/*
 测试按钮不绘制焦点状态
 */
public class JButtonDemo {
    public static void main(String[] args) {
        JFrame frame = new JFrame("测试绘制焦点状态");
        frame.setLayout(null);
        JPanel panel = new JPanel();
        panel.setBounds(140,100,100,40);
        frame.setSize(new Dimension(400, 300));
        JButton button = new JButton("普通按钮");
        // 设置 paintFocus 属性,设置为false 则不会绘制焦点状态
        button.setFocusPainted(false);

        // 添加按钮
        panel.add(button);
        frame.add(panel);
        // 获取焦点
        frame.setFocusable(true);
        // 居中显示
        frame.setLocationRelativeTo(null);
        // 设置可见
        frame.setVisible(true);
    }
}

以上就是 网页直播源码,JButton去掉按钮字周围的虚线框,更多内容欢迎关注之后的文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值