gpt4 book ai didi

java - 删除 JButton 矩形白色边框

转载 作者:行者123 更新时间:2023-12-01 04:43:38 26 4
gpt4 key购买 nike

有人知道如何删除 JButton 上的白色矩形边框吗?仅当按钮有点圆润时,此问题才会出现在 Windows 外观和感觉中。

请查找附件中图像 enter image description here 上的示例.

将边框设置为空或 null 没有帮助。 margin 也是如此。

仅当我将按钮的不透明度设置为 false 时,白色边距/边框才会消失,但不幸的是,在这种情况下,整个按钮在某些版本的 Windows 上也是不透明的。

当我将不透明度设置为 false 时,它​​看起来像: enter image description here

代码示例:

public class TestFrame extends javax.swing.JFrame {

/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {

try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}

TestFrame inst = new TestFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}

public TestFrame() {

this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setLayout(null);
this.getContentPane().setBackground(Color.BLACK);

JButton button = new JButton();
button.setBounds(10, 10, 100, 50);
button.setBorder(BorderFactory.createEmptyBorder()); // not working
button.setBorder(null); // not working
button.setMargin(new Insets(0,0,0,0)); // not working

add(button);
pack();
setSize(400, 300);
}

}

谢谢,卢博斯

最佳答案

看起来像是绘画问题。您可以使用:

button.setBackground( Color.BLACK );

关于java - 删除 JButton 矩形白色边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150565/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com