Swing本来提供的滑块JSlider丑的实在不忍直视,所以很有必要进行优化重写
提供有两种方法进行JSlider的美化
运用look and feel
那什么是 LookAndFeel 呢?
通俗的说,这就是皮肤;
从功能上说。这是一种批量管理 Swing 控件外观的机制;
从根源来说,这是 Swing 的核心。
在Swing中只需一行代码就可以改变皮肤UIManager.setLookAndFeel(new LookAndFeel());
比如:UIManager.setLookAndFeel(new QuaquaLookAndFeel());
我们还可以通过UIManager.setLookAndFeel(String s);
来改变外观,其中,s是表示该外观的路径,比如UIManager.setLookAndFeel("org.fife.plaf.OfficeXP.OfficeXPLookAndFeel");
以下是一些java自带的look and feel,当然还可以去网上下载其他的.
UIManager.setLookAndFeel(com.sun.java.swing.plaf.windows.WindowsLookAndFeel.class.getName());//还可以,只能在windows系统中用,也就是这句代码不跨平台
UIManager.setLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel.class.getName());//还可以
UIManager.setLookAndFeel(javax.swing.plaf.basic.Bas