2012-03-24 85 views
1

當我在使用半透明的jFrame中有jComboBox時,似乎存在問題。當我點擊下拉菜單時,白色背景似乎會覆蓋其他組件,但下拉菜單中的項目不會顯示。只有當我的鼠標懸停在它上面時,每個項目纔會出現。邊界似乎也沒有。JDK7半透明+ jframe + jcombobox

針對此問題的任何解決方法?

謝謝!

+0

也許你會提供一些代碼片段,這樣一個可以幫助你? – Jagger 2012-04-04 19:11:10

回答

2

我也面臨同樣的問題。

快速修復:

import java.awt.*; 
import javax.swing.*; 
import javax.swing.event.*; 
class WindowOpaqueTest2{ 
    public JComponent makeUI() { 
    JPanel p = new JPanel(); 
    p.setBackground(new Color(.5f,.5f,.5f,.5f)); 
    p.add(new JComboBox<String>(new String[] {"aaa", "bb", "c"})); 
    JComboBox c = new JComboBox<String>(new String[] {"aaa", "bb", "c"}); 
    c.addPopupMenuListener(new PopupMenuListener() { 
     @Override public void popupMenuWillBecomeVisible(final PopupMenuEvent e) { 
     EventQueue.invokeLater(new Runnable() { 
      @Override public void run() { 
      JComboBox c = (JComboBox)e.getSource(); 
      Object o = c.getAccessibleContext().getAccessibleChild(0); 
      if(o instanceof JComponent) { //BasicComboPopup 
       ((JComponent)o).repaint(); 
      } 
      } 
     }); 
     } 
     @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} 
     @Override public void popupMenuCanceled(PopupMenuEvent e) {} 
    }); 
    p.add(c); 
    return p; 
    } 
    public static void main(String[] args) { 
    EventQueue.invokeLater(new Runnable() { 
     @Override public void run() { createAndShowGUI(); } 
    }); 
    } 
    public static void createAndShowGUI() { 
    JFrame.setDefaultLookAndFeelDecorated(true); 
    JFrame f = new JFrame(); 
    //com.sun.awt.AWTUtilities.setWindowOpaque(f, false); 
    f.setBackground(new Color(0,true)); //1.7.0 
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
    f.getContentPane().add(new WindowOpaqueTest2().makeUI()); 
    f.setSize(320, 240); 
    f.setLocationRelativeTo(null); 
    f.setVisible(true); 
    } 
} 
+0

感謝您的解決 – mKorbel 2012-07-10 20:06:25