简体   繁体   中英

How to vertically align two JSlider objects independent of tick labels

I am using several horizontally positioned JSlider objects in my Java application and would like to align their left and right track ends vertically. That means whenever two knobs are positioned on the left end of their track the upper knob should be exactly above the lower one without any displacement in horizontal direction.

The problem I currently have is that long labels at ticks on the left or right end of a track decrease the length of the track and do not allow a nice alignment. As an example, see the following image:

JSlider alignment problem example

Does anyone know how to vertically align the tracks of two horizontally positioned JSlider objects independent of their tick labels ?

A solution for my problem might be to left-align/right-align labels at the end of the track (ie the label on the far left tick is left-aligned to its tick), but I did not find out how I could do that. Maybe there is also a better solution I did not think about.

Thanks, Sandreal

我不认为JSlider标签可以通过这样的方式访问,你可以编辑它们的位置,所以你应该创建单独的标签并相对于JSlider自己定位,然后你可以确定它们不会影响JSlider(取决于您的布局管理器)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM