JTattoo 对于JCombox(下拉框)显示不正常?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37355951/article/details/79259709

JTattoo是java的界面包装工具,美化你的swing界面。但是在用的过程中发现JCombox显示不正常,如图所示

注意要在官网上下载jar,然后引入到你工程中:下载jar


代码如下:

public class JTattooTest {
	public static void main(String[] args) {
		JFrame frame = new JFrame("JTattoo测试");
		frame.setLayout(new FlowLayout());
		JComboBox<String> com = new JComboBox<>();
		com.addItem("选项一");
		com.addItem("选项二");
		frame.add(com);
		frame.setSize(new Dimension(300, 200));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		try {
			UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
				| UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
关键一句就是 UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
字符串对应是不同风格的类。利用反射创建对象。

其他预设主题参考官网:预设主题   在eclipse下按Ctrl+T 找到对应类的类路径替换上面即可

解决办法就是将这段代码放到最前面即可

代码如下:

public class JTattooTest {
	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
				| UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JFrame frame = new JFrame("JTattoo测试");
		frame.setLayout(new FlowLayout());
		JComboBox<String> com = new JComboBox<>();
		com.addItem("选项一");
		com.addItem("选项二");
		frame.add(com);
		frame.setSize(new Dimension(300, 200));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		
	}
}

猜你喜欢

转载自blog.csdn.net/m0_37355951/article/details/79259709