英文:
How to make JButton borderless in Netbeans?
问题
我正在尝试改进我的Netbeans项目的Java GUI,下面是我的项目在Netbeans设计工具中的图片,这4个文本实际上是我设置为false的JButton,以改善设计。
但是在下面的图片中,您可以看到结果与应该看起来的样子相差很大,即使我将其设置为false,边框仍然存在,我不知道如何让它看起来像上面的图片,我已经提供了下面的代码供您参考。
代码如下:(如您所见,我已经设置了setBorderPainted(false),我以为这会起作用,但事实并非如此)
HomeButton = new javax.swing.JButton();
HomeButton.setBackground(new java.awt.Color(102, 102, 102));
HomeButton.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
HomeButton.setForeground(new java.awt.Color(255, 255, 255));
HomeButton.setText("Home");
HomeButton.setBorderPainted(false);
HomeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
HomeButtonActionPerformed(evt);
}
});
如果您知道如何使我的代码的结果看起来像第一张图片,请告诉我。谢谢。
英文:
Im trying to improve the Java GUI of my project in Netbeans, below is the picture of my project in Netbeans's design palette , the 4 texts are actually JButtons which I have set the Border to false to improve the design.
However in the picture below, you can see the result is quite different from what it should look like and the borders are still there even when I set it as false, I do not know how to get it to look like the picture on top, Ive provided the code for this below for your reference.
Code here: (as you can see I already setBorderPainted(false) which I thought will do the trick but no)
HomeButton = new javax.swing.JButton();
HomeButton.setBackground(new java.awt.Color(102, 102, 102));
HomeButton.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
HomeButton.setForeground(new java.awt.Color(255, 255, 255));
HomeButton.setText("Home");
HomeButton.setBorderPainted(false);
HomeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
HomeButtonActionPerformed(evt);
}
});
If you know how to get the result of my code to look like the first image please do update me. Thank you.
答案1
得分: 1
尝试使用以下代码:
HomeButton.setContentAreaFilled(false);
以及:
HomeButton.setBorderPainted(false);
在这种情况下,我认为不需要设置背景颜色,但我不确定。
英文:
Try with:
HomeButton.setContentAreaFilled(false);
along with:
HomeButton.setBorderPainted(false);
... in which case I think setting the background color is not needed, but I am not sure.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论