简体   繁体   English

从 JButton 移除边框

[英]Remove border from JButton

I would have a problem with the edges of my jbutton .我的jbutton的边缘会有问题。 In practice, in the code below I inserted a button that should not have edges but instead appear as in the photo below.实际上,在下面的代码中,我插入了一个不应有边缘但如下图所示的按钮。

        JButton btnRes = new JButton();
        btnRes.setBorderPainted(false);
        btnRes.setContentAreaFilled(false);
        btnRes.setOpaque(false);
        btnRes.setBorder(null);
        btnRes.setIcon(new ImageIcon(Main.class.getResource(image1)));
        btnRes.setPressedIcon(new ImageIcon(Main.class.getResource(image2)));
        btnRes.setRolloverIcon(new ImageIcon(Main.class.getResource(image3)));
        btnRes.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            //TODO
            }
        });
        btnRes.setBounds(496, 342, 138, 48);
        frame.getContentPane().add(btnRes); 

and this is the result:这是结果:

Image of this JButton此 JButton 的图像

The border is however visible, how I can fix this?但是边框是可见的,我该如何解决这个问题?

You see the border that is added to the button because it is selected.您会看到添加到按钮的边框,因为它被选中。 Try:尝试:

btnRes.setFocusPainted(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM