Swing slider问题
滑块,怎么配上数字。。。如果有12个数字,需要配12个lable? --------------------编程问答-------------------- 是的。给你个小代码Code:
slide=new JSlider();
slide.setMaximum(500);
slide.setMinimum(0);
slide.setMajorTickSpacing(100);
slide.setPaintLabels(true);
slide.setPaintTicks(true);
slide.setOpaque(false);
slide.setOrientation(JSlider.VERTICAL);
int max = slide.getMaximum();
int min = slide.getMinimum();
int gap = slide.getMajorTickSpacing();
int size = (max - min) / gap;
Hashtable list = new Hashtable();
for (int i = 0; i < size + 1; i++) {
JLabel label = new JLabel(i * 100 + "%");
label.setFont(new Font("Dialog", Font.ITALIC, 9));
list.put(new Integer(i * 100), label);
}
slide.setLabelTable(list);
补充:Java , Java SE