0
您好我已經在linux平臺的java中創建了一個滑塊。但滑塊在不同的操作系統中給出了不同的外觀和感覺。意味着在Linux中它看起來有點不錯,但在Mac操作系統中,滑塊看起來不同。所以不管操作系統如何給我的滑塊賦予相同的外觀和感覺我在java中的滑塊並沒有在所有平臺上給出相同的外觀和感覺
代碼如下。
import javax.swing.JFrame; import javax.swing.JSlider; import javax.swing.Timer;
public class Test {
static int percent = 0;
public static void main(String[] args) {
JFrame f = new JFrame();
final JSlider s = new JSlider();
f.getContentPane().add(s);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
Timer time = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
percent++;
if (percent>100)
percent = 0;
// s.setMajorTickSpacing(10); //s.setMinorTickSpacing(1); //s.setPaintTicks(true); //s.setPaintLabels(true);
// JScrollBar sb = s.getHorizontalScrollBar(); s.setValue((int)(s.getMaximum()*(percent/100.0))); s.setAutoscrolls(true); } }); time.start(); }
}
感謝 蘇尼爾·庫馬爾Sahoo
好吧,不同的外觀和感覺點,他們看起來不同。但請查看靈氣或金屬,它們應該在每個平臺上看起來幾乎相同 – clamp 2009-09-27 12:13:03
(請注意,除了包括主線程在內的AWT事件調度線程(EDT)之外,您不應該使用Swing。標準樣板:'java.awt.EventQueue.invokeLater(new Runnbale(){public void run(){...}})''。 – 2009-09-27 13:51:52