简体   繁体   English

如何更改JComboBox的用户界面

[英]How do i change the UI of a JComboBox

I like to change the UI of a JComboBox from the default metal look to some custom UI, see attached image. 我想将JComboBox的用户界面从默认的金属外观更改为一些自定义用户界面,请参见附件图像。

样品

I have tried changing all the UIDefaults for the JComboBox but to no success. 我尝试过更改JComboBox的所有UIDefaults,但没有成功。

How does one achieve this? 如何做到这一点?

jdk1.4.2 JDK1.4.2

You have to write your own ComboBoxUI class. 您必须编写自己的ComboBoxUI类。 I suggest to look at either Synth or Nimbus Look and Feel to make it easier. 我建议您查看Synth或Nimbus外观,以使其更容易。

您需要更改箭头图像,并在样式上为此JComboBox更改背景!

use WindowsLookAndFeel; 使用WindowsLookAndFeel;

this works if and only if you are running your application in winows; 仅当您在Windows中运行应用程序时,此方法才有效;

in your main you can do this before creating any UI: 您可以在创建任何UI之前先执行以下操作:


try{
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception ignore){
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM