2016-11-18 33 views
2

我有这种情况(JSlider在不需要时显示值)。我不想在JSlider上显示当前的价值。JSlider隐藏值GTK +和Nimbus LookAndFeel在Linux上

  1. 为什么只在Linux上使用LookAndFeel Nimbus和GTK +显示JSlider的值?
  2. 如何隐藏此值?

下一个图像显示在Windows 10美分OS 7和MacOS运行代码塞拉利昂

enter image description here

enter image description here

这里我的代码:

import java.awt.BorderLayout; 
import java.awt.Container; 
import java.awt.Dimension; 
import java.awt.EventQueue; 
import javax.swing.Box; 
import javax.swing.BoxLayout; 

import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JSlider; 

import javax.swing.SwingUtilities; 
import javax.swing.UIManager; 
import javax.swing.UnsupportedLookAndFeelException; 

public class JSliderLAF { 

    public static void changeLAF(Container container, String laf) { 
    try { 
     UIManager.setLookAndFeel(laf); 
    } catch (ClassNotFoundException | InstantiationException | 
     IllegalAccessException | UnsupportedLookAndFeelException e) { 
    } 
    SwingUtilities.updateComponentTreeUI(container); 
    } 

    public static void main(String args[]) { 
    EventQueue.invokeLater(() -> { 
     JPanel jpVert = new JPanel(); 
     jpVert.setLayout(new BoxLayout(jpVert, BoxLayout.PAGE_AXIS)); 
     for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { 
     JSlider jsl = new JSlider(); 
     jsl.setMajorTickSpacing(20); 
     jsl.setMinorTickSpacing(5); 
     jsl.setPaintLabels(true); 
     jsl.setPaintTicks(true); 
     jsl.setSnapToTicks(true); 
     JPanel jpHorz = new JPanel(); 
     jpHorz.setLayout(new BoxLayout(jpHorz, BoxLayout.LINE_AXIS)); 
     JLabel jlName = new JLabel(info.getName() + " : "); 
     JLabel jlClass = new JLabel(info.getClassName()); 
     jpHorz.add(jsl); 
     jpHorz.add(Box.createRigidArea(new Dimension(5,0))); 
     jpHorz.add(jlName); 
     jpHorz.add(Box.createRigidArea(new Dimension(2,0))); 
     jpHorz.add(jlClass); 
     jpHorz.add(Box.createRigidArea(new Dimension(2,0))); 
     jpHorz.add(Box.createHorizontalGlue()); 
     changeLAF(jsl,info.getClassName()); 
     jpVert.add(jpHorz); 
     } 
     final JFrame frame = new JFrame(); 
     frame.add(jpVert, BorderLayout.NORTH); 
     frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
     frame.pack(); 
     frame.setVisible(true); 
    }); 
    }   
} 
+0

答案t o第一个问题是因为GTK +默认这样做。我不知道第二个问题的答案,唉。我知道用一个实际的GTK +滑动条[this](https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-set-draw-value)是方法(它也通过'draw-value'GObject属性)将会做到这一点。 – andlabs

+0

谢谢,但Nimbus?灵气也是呈现这个价值。 –

+0

如果仔细观察,Nimbus滑块看起来与GTK +滑块完全相同。我假设Nimbus只是在自定义样式上使用GTK +。 – andlabs

回答

2
public static void changeLAF(Container container, String laf) { 
    try { 
    UIManager.setLookAndFeel(laf); 
    UIManager.put("Slider.paintValue", false); 
    } catch (ClassNotFoundException | InstantiationException | 
     IllegalAccessException | UnsupportedLookAndFeelException e) { 
    } 
    SwingUtilities.updateComponentTreeUI(container); 
}