如何返回JSlider当前刻度的值 50
importjava.awt.BorderLayout;importjava.util.Hashtable;importjavax.swing.*;publicclass...
import java.awt.BorderLayout;
import java.util.Hashtable;
import javax.swing.*;
public class T {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
Hashtable labelTable = new Hashtable();
for (int i = 0; i <= 100; i += 10) {
labelTable.put(new Integer(i),
new JLabel(String.valueOf(i / 100.0)));
}
JSlider slider = new JSlider();
slider.setLabelTable(labelTable);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setMajorTickSpacing(10);
slider.setMinorTickSpacing(5);
JFrame f = new JFrame();
f.getContentPane().add(slider, BorderLayout.CENTER);
f.setSize(500, 200);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
刻度用哈希表弄成小数了,但怎么返回滑块当前刻度的值??求助 展开
import java.util.Hashtable;
import javax.swing.*;
public class T {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
Hashtable labelTable = new Hashtable();
for (int i = 0; i <= 100; i += 10) {
labelTable.put(new Integer(i),
new JLabel(String.valueOf(i / 100.0)));
}
JSlider slider = new JSlider();
slider.setLabelTable(labelTable);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setMajorTickSpacing(10);
slider.setMinorTickSpacing(5);
JFrame f = new JFrame();
f.getContentPane().add(slider, BorderLayout.CENTER);
f.setSize(500, 200);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
刻度用哈希表弄成小数了,但怎么返回滑块当前刻度的值??求助 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询