放置边框后没有启用JButton(Java)

时间:2016-05-04 02:38:15

标签: java swing jbutton

 import java.awt.*;
 import javax.swing.*;
 import javax.swing.border.Border;

public class Test extends JFrame {

    public Test() {

       JButton button = new JButton();
       Border buttonBorder = BorderFactory.createLineBorder(Color.BLACK, 1); // create a line border with the specified color and width
       button.setBorder(buttonBorder); // set the border of this component
       button.setPreferredSize(new Dimension(50,50));
       add(button);

       setVisible(true);
       pack();
    }

    public static void main(String[] args) {
       Test t = new Test();
    }
}

基本上,如果我要注释第7行和第8行然后运行代码,则按钮是可点击的。但是,如果我确实放了边框,按钮就会处于休眠状态,我无法点击它。

0 个答案:

没有答案