gpt4 book ai didi

java - JDK7半透明+jframe+jcombobox

转载 作者:行者123 更新时间:2023-11-30 04:50:51 26 4
gpt4 key购买 nike

当我在使用半透明的 jFrame 中有一个 jComboBox 时,似乎存在问题。当我单击下拉列表时,白色背景会覆盖其他组件,但下拉列表中的项目不会显示。每个项目仅在我的鼠标悬停在其上时出现。边界似乎也不在附近。

有什么解决办法吗?

谢谢!

最佳答案

我也面临着同样的问题。

快速修复:

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);
}
}

关于java - JDK7半透明+jframe+jcombobox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9850193/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com