本文介绍了更改JSlider的可显示标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个最小为0,最大为10,000的JSlider。我的主刻度标记设置为1,000。如果我现在要绘制标签,它们将显示为0,1000,2000,3000,4000等。我想要显示的内容将是0,1,2,3,4,5等。是一个完成这项任务的好方法吗?

I have a JSlider with a min of 0 and a max of 10,000. I have the major tick marks set at 1,000. If I were to paint the labels now they would show up as 0, 1000, 2000, 3000, 4000, etc. What I would like to be shown would be 0, 1, 2, 3, 4, 5, etc. What would be a good way to accomplish this task?

推荐答案

使用

EDIT

或者你可以依赖预定义的标签UI,只需更改标签文字:

Alternatively you can rely on predefined label UI and just change the label text:

    Enumeration e = jSlider.getLabelTable().keys();

    while (e.hasMoreElements()) {
        Integer i = (Integer) e.nextElement();
        JLabel label = (JLabel) jSlider.getLabelTable().get(i);
        label.setText(String.valueOf(i / 1000));
    }

这篇关于更改JSlider的可显示标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 17:44