2010-05-02 34 views
8

我的Windows 7機器上的垂直JSlider旋鈕(具有本機外觀)在兩個方向上確實非常小。不只是瘦,但也很短。 alt text http://img101.imageshack.us/img101/8946/verticalsliderproblemwi.jpgWindows 7外觀上的Java Swing渲染錯誤?

任何人都可以證實這一點嗎?我應該報告嗎?如果是這樣,在哪裏?謝謝!

下面是示例程序的代碼(在屏幕截圖):

import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.JSlider; 
import javax.swing.SwingConstants; 
import javax.swing.UIManager; 


public class SliderTest 
{ 
    public static void main(String[] args) 
    { 
     // Set the look and feel to that of the system 
     try 
     { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } 
     catch (Exception e) 
     { System.err.println(e); } 


     // Launch the GUI from the event dispatch thread 
     javax.swing.SwingUtilities.invokeLater(new Runnable() 
     { 
      public void run() 
      { 
       JFrame window = new JFrame(); 
       window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

       JPanel contentPane = new JPanel(); 
       contentPane.add(new JSlider(SwingConstants.HORIZONTAL)); 
       contentPane.add(new JSlider(SwingConstants.VERTICAL)); 

       window.setContentPane(contentPane); 
       window.pack(); 
       window.setLocationRelativeTo(null); // Center window 
       window.setVisible(true); 
      } 
     }); 
    } 
} 
+0

不知道這是否是一個錯誤,但我看到了同樣的事情。 – foxwoods 2010-05-02 18:02:26

+0

我認爲值得讓Sun,呃,甲骨文可以看到; P我想我會在bugs.sun.com上發佈一些東西(我認爲這是去的地方?)。 – Vimes 2010-05-02 19:10:00

+0

對於所有安裝的L&F,Mac OS X 10.5.8 Java 1.6看起來都很正常。這是'FlowLayout'的工件嗎,'JPanel'的默認值? – trashgod 2010-05-03 03:44:34

回答

4

首先,這種情況發生在Windows Vista中了。似乎是這樣,滑塊試圖佔用儘可能小的空間。如果你想要一個更大的JSlider使用JSlider.setPaintTicks。所以你必須添加以下內容:

JSlider vertical = new JSlider(SwingConstants.VERTICAL); 
vertical.setPaintTicks(true); 
contentPane.add(vertical); 

這應該做的伎倆。