Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java: How do I display a large number of numbers and tick marks on a JSlider? Th

ID: 643281 • Letter: J

Question

Java: How do I display a large number of numbers and tick marks on a JSlider?

The below squished the display of numbers and tick marks.

public Window() {
setTitle("Test Window Title");
setSize(1000, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 800, 500);
  
slider.setMajorTickSpacing(100);
slider.setMinorTickSpacing(25);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
  
JPanel panel = new JPanel();
  
panel.add(slider);
  
add(panel);

setVisible(true);
}

Explanation / Answer

My Swing application uses Sliders. AjaxSwing converts them to HTML and the sliders
and value fields work properly.
However, the numerical labels on the JSlider tick marks do not show up on the HTML page.

I took a closer look at SwingSet2 demo JSlider tab.
The original Sun/Oracle application shows numbers on the third Slider (both horizontal and vertical versions).
However the AjaxSwing converted version of JSlider tab does not show the corresponding numbers.
This appears to be a bug.

Is there a workaround or can you fix this in AjaxSwing. It is a critical feature to replicate JSliders.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote