Ste*_*eod 6 java swing jcombobox
当我在Windows 7上使用JComboBox时,四个角的每个角都有一个与父组件的背景颜色不匹配的像素.
在Windows 8中,这个问题不会发生(尽管这可能是因为在Windows 8中,JComboBox被渲染为完美的矩形).它也不会发生在OS X上.
我该怎么做才能使角落像素让父组件的背景颜色通过?
这是显示问题的图像:

这是我正在使用的一个独立的代码示例:
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
} catch (Exception e) {
e.printStackTrace();
}
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
JComboBox<String> comboBox = new JComboBox<String>(new String[]{"One", "Two"});
contentPane.add(comboBox);
JFrame frame = new JFrame("JComboBox Test");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setContentPane(contentPane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
尝试去掉边框...
comboBox.setBorder(null);
Run Code Online (Sandbox Code Playgroud)

下一个选择是设计一个专门的外观和感觉委托来实现您在 Windows 上想要的东西......
例如...
public static class MyComboBoxUI extends WindowsComboBoxUI {
@Override
protected void installDefaults() {
super.installDefaults();
LookAndFeel.uninstallBorder(comboBox);
}
public static ComponentUI createUI(JComponent c) {
return new MyComboBoxUI();
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用...安装它
UIManager.put("ComboBoxUI", MyComboBoxUI.class.getName());
Run Code Online (Sandbox Code Playgroud)
这意味着您不需要删除创建的每个组合框的边框
UIManager或者,您可以简单地覆盖...中的默认边框属性。
UIManager.put("ComboBox.border", new EmptyBorder(0, 0, 0, 0));
Run Code Online (Sandbox Code Playgroud)
无论哪种方式,它都会影响应用它后创建的所有组合框......
| 归档时间: |
|
| 查看次数: |
354 次 |
| 最近记录: |