[英]JButton margins. Not respected when nimbus plaf
The property margin
of a JButton
isn't respected when the nimbus look and feel is installed. 安装了雨云外观后,不会遵守
JButton
的属性margin
。
. 。 I need some "little" buttons, but nimbus forces the space around button text to be large, so I only get "very large" buttons.
我需要一些“小”按钮,但是nimbus强制按钮文本周围的空间很大,所以我只得到“非常大”的按钮。
I discovered in nimbus defaults page that there is a property called: 我在nimbus默认页面中发现有一个名为的属性:
Button.contentMargins
that is preset with large values. 预设大值。
I've tryed to override it with the following code: 我试着用以下代码覆盖它:
UIManager.getDefaults().put("Button.contentMargins", new InsetsUIResource(0,0,0,0));
in the main
, just after setting the nimbus look and feel. 在
main
,刚设置了灵气的外观和感觉。
But nothing happens, the empty space around buttons text still remains large. 但没有任何反应,按钮文本周围的空白区域仍然很大。 Any idea?
任何的想法?
更改JComponent.sizeVariant
的值也可能是有效的,如调整组件大小中所述 。
on base of thread How to change the background color for JPanels with Nimbus Look and Feel? 在线程的基础上如何使用Nimbus外观改变JPanels的背景颜色? is possible to change and assign one value for something from
Nimbus Defaults
, 可以更改并为
Nimbus Defaults
某个值分配一个值,
but are you sure that you needed this output to the GUI, nothing nice 但是你确定你需要这个输出到GUI,没什么好看的
vs basic JButton with Nimbus L&F 与基本的JButton与Nimbus L&F
from code 来自代码
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.InsetsUIResource;
public class NimbusJPanelBackGround {
public NimbusJPanelBackGround() {
JButton btn = new JButton(" Whatever ");
JButton btn1 = new JButton(" Whatever ");
JPanel p = new JPanel();
p.add(btn);
p.add(btn1);
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.add(p, BorderLayout.CENTER);
f.setSize(200, 100);
f.setLocation(150, 150);
f.setVisible(true);
}
public static void main(String[] args) {
try {
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
UIManager.getLookAndFeelDefaults().put("Panel.background", Color.white);
UIManager.getLookAndFeelDefaults().put("Button.contentMargins", new InsetsUIResource(0,0,0,0));
}
}
} catch (Exception e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
NimbusJPanelBackGround nimbusJPanelBackGround = new NimbusJPanelBackGround();
}
});
}
}
previously +1 for interesting question 以前为有趣的问题+1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.