1

I want to use a Vertical JSlider, but only showing the slider thumb (Not track, ticks, labels). When the thumb is pressed then hidden properties are shown. Maybe is confuse explain my idea, like the arrowButton of JComboBox is pressed and the JComboBox is unfolded (drop-down list).

Some example.

I don't know where to start, some clue?

How to hide the all Background of JSlider and Show when the Knob is Selected?

I was reading JComboBox, ComboBoxEditor, BasicComboBoxEditor...

http://www.java2s.com/Tutorial/Java/0240__Swing/CustomizingaJSliderLookandFeel.htm

How do I make a JSlider background transparent? or How do I properly overlay JComponents in JLayeredPane?

Painting the slider icon of JSlider

how to put an image over jslider's knob image when mouse is present over the knob's image

enter image description here

Changing BasicSliderUI.

This is my Code:

JPanel jpEmpty = new JPanel();
jpEmpty.setLayout(new BoxLayout(jpEmpty, BoxLayout.LINE_AXIS));
JSlider sliderEmpty = new JSlider(SwingConstants.VERTICAL);
sliderEmpty.addMouseListener(new MouseInputListener() {
  @Override
  public void mouseDragged(MouseEvent e) {
    System.out.println("mouseDragged(x:" + e.getX() + " , y:"+ e.getY() + ")");
  }
  @Override
  public void mousePressed(MouseEvent e) {
    sliderEmpty.setPaintTrack(true);
    System.out.println("mousePressed(x:" + e.getX() + " , y:"+ e.getY() + ")");
  }
  @Override
  public void mouseReleased(MouseEvent e) {
    sliderEmpty.setPaintTrack(false);
    System.out.println("mouseReleased(x:" + e.getX() + " , y:"+ e.getY() + ")");
  }
  @Override
  public void mouseClicked(MouseEvent e) {
  }
  @Override
  public void mouseEntered(MouseEvent e) {
  }
  @Override
  public void mouseExited(MouseEvent e) {
  }
  @Override
  public void mouseMoved(MouseEvent e) {
  }
});
jpEmpty.add(sliderEmpty);
jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.PAGE_AXIS));
jPanel1.add(Box.createRigidArea(new Dimension(0,5)));
jPanel1.add(jpEmpty);
jPanel1.add(Box.createRigidArea(new Dimension(0,5)));
setLayout(new BorderLayout());
add(jPanel1);
pack();
validate();

enter image description here ReleasedThumb

enter image description here PressedThumb

ALTERNATIVE Option changing JSlider Size dinamically!

JSlider slideResize = new JSlider(SwingConstants.VERTICAL);
int thumbHeight = UIManager.getLookAndFeelDefaults().getInt("Slider.thumbHeight");
int thumbWidth = UIManager.getLookAndFeelDefaults().getInt("Slider.thumbWidth");
Dimension newResizeDim = new Dimension(thumbWidth, thumbHeight);//Size For Released Knob/Thumb
Dimension oldResizeDim = ((BasicSliderUI)slideResize.getUI()).getPreferredVerticalSize();//Size For Pressed Knob/Thumb
slideResize.setPreferredSize(new Dimension(thumbWidth, thumbHeight));//Change to Small size by Default
slideResize.addMouseListener(new MouseInputListener() {
  @Override
  public void mouseDragged(MouseEvent e) {
    System.out.println("mouseDragged(x:" + e.getX() + " , y:"+ e.getY() + ")");
  }
  @Override
  public void mousePressed(MouseEvent e) {
    slideResize.setPreferredSize(oldResizeDim);
    System.out.println("mousePressed(x:" + e.getX() + " , y:"+ e.getY() + ")");
  }
  @Override
  public void mouseReleased(MouseEvent e) {
    slideResize.setPreferredSize(newResizeDim);
    System.out.println("mouseReleased(x:" + e.getX() + " , y:"+ e.getY() + ")");
  }
  @Override
  public void mouseClicked(MouseEvent e) {
  }
  @Override
  public void mouseEntered(MouseEvent e) {
  }
  @Override
  public void mouseExited(MouseEvent e) {
  }
  @Override
  public void mouseMoved(MouseEvent e) {
  }
});
setLayout(new BorderLayout());
add(slideResize);
pack();
validate();

The problem is It Actually doesn't Resize

enter image description here ReleasedThumb

enter image description here PressedThumb

3. But How to Achieve the behaviour like JComboBox Exceeding (protruding from the boundary) the Limit JFrame?

enter image description here

enter image description here

Community
  • 1
  • 1
QA_Col
  • 1,095
  • 9
  • 23

0 Answers0