当我运行我的应用程序时,按钮颜色没有得到更新,而是没有正常显示以及动态显示。此问题仅在 Linux 环境中发生,并且相同的代码在 Windows 上也可以正常工作。
private JButton button = new JButton();
button.setLayout(buttonLayout);
button.add(totalsLabel, BorderLayout.CENTER);
totalsLabel.setHorizontalAlignment(JButton.CENTER);
button.add(statusLabel, BorderLayout.SOUTH);
statusLabel.setHorizontalAlignment(JButton.CENTER);
button.setMargin(new Insets(0, 0, 0, 0));
button.setVerticalAlignment(SwingConstants.TOP);
button.setHorizontalTextPosition(SwingConstants.CENTER);
button.setEnabled(true);
button.setPreferredSize(PREFERRED_SIZE);
button.setRequestFocusEnabled(false);
button.setVerifyInputWhenFocusTarget(false);
button.setFocusPainted(false);
button.setBackground(mementoTO.getBackGroundColor());
private void initializeAlternatingColorsThread() {
alternatingColors = new Thread(new Runnable() {
public void run() {
while(true) {
while(continueAlternatingColors()) {
try {
if(button.getBackground().equals(BACKGROUND_PAY_LATER)) {
button.setBackground(BACKGROUND_BUSY); }
else {
button.setBackground(BACKGROUND_PAY_LATER); }
Thread.sleep(500); }
catch(InterruptedException ex) {
getLogger().error(this + " - Error occured in initializeAlternatingColorsThread: ", ex); } }
synchronized(lockVariable) {
try {
lockVariable.wait(); }
catch(InterruptedException e) {
} } } }
}, "AlternatingColors"); }
GuiExecutor.getInstance().update(new Runnable() {
public void run() {
setStaticText("RESETTING PUMP");
setStatus("HANG UP NOZZLE");
button.setBackground(BACKGROUND_BUSY);
button.repaint();
} });
如果我继续使用 Windows 的外观和感觉,那么我在 Linux 中会遇到异常。所以我改变了外观并作为 Linux 的 GDK。
INFO | jvm 1 | main | 2013/01/21 15:14:23.995 | Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
INFO | jvm 1 | main | 2013/01/21 15:14:23.995 | at javax.swing.plaf.basic.BasicButtonUI.getMinimumSize(BasicButtonUI.java:352)
INFO | jvm 1 | main | 2013/01/21 15:14:23.995 | at javax.swing.JComponent.getMinimumSize(JComponent.java:1714)
INFO | jvm 1 | main | 2013/01/21 15:14:23.995 | at java.awt.BorderLayout.minimumLayoutSize(BorderLayout.java:651)
INFO | jvm 1 | main | 2013/01/21 15:14:23.995 | at java.awt.Container.minimumSize(Container.java:1651)
INFO | jvm 1 | main | 2013/01/21 15:14:23.995 | at java.awt.Container.getMinimumSize(Container.java:1636)
INFO | jvm 1 | main | 2013/01/21 15:14:23.996 | at javax.swing.JComponent.getMinimumSize(JComponent.java:1716)
INFO | jvm 1 | main | 2013/01/21 15:14:23.996 | at java.awt.FlowLayout.minimumLayoutSize(FlowLayout.java:448)
INFO | jvm 1 | main | 2013/01/21 15:14:23.996 | at