按鈕顏色沒有得到更新,而是在我運行我的應用程序時沒有正常顯示以及動態顯示。這個問題只發生在Linux環境中,並且相同的代碼可以很好地與Windows一起工作。Linux平臺中的按鈕顏色問題
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下得到的異常。所以我改變了外觀和GDK for Linux。
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
我得到了在那裏我得到這個異常的地方。 button.add(totalsLabel,BorderLayout.CENTER); totalsLabel.setHorizontalAlignment(JButton.CENTER); button.add(statusLabel,BorderLayout.SOUTH); statusLabel.setHorizontalAlignment(JButton.CENTER); – user1280096 2013-02-22 06:51:04
@ user1280096:請注意任何更改作爲原始問題的補充。編輯原始問題,在最後添加新代碼並添加新解釋,然後評論我們的答案以通知我們有關更改。 – 2013-02-22 11:54:39