Można spróbować samemu zrobić:
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JSlider;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JWindow;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main extends JFrame {
private XSlider x = null;
public Main() {
super("XSlider test");
setSize(400,300);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
x = new XSlider(0, 100, 50);
getContentPane().add(x);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
class XSlider extends JComponent {
private JSlider slider = null;
private JTextField value = null;
private BasicArrowButton arrow = null;
private JWindow window = null;
public XSlider(int minValue, int maxValue) {
super();
setLayout(new BoxLayout(this, BoxLayout.X_AXIS) );
slider = new JSlider(minValue, maxValue);
initComponents();
}
public XSlider(int minValue, int maxValue, int value) {
super();
setLayout(new BoxLayout(this, BoxLayout.X_AXIS) );
slider = new JSlider(minValue, maxValue, value);
initComponents();
}
private void initComponents() {
slider.setPaintLabels(false);
slider.setPreferredSize(new Dimension(100, slider.getPreferredSize().height) );
slider.addChangeListener(new XSliderChangeListener());
value = new JTextField(""+slider.getValue(), 3);
value.setEditable(false);
value.setBackground(Color.WHITE);
value.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
value.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
window.setVisible(!window.isVisible());
}
});
arrow = new BasicArrowButton(BasicArrowButton.EAST);
arrow.setActionCommand("showDialog");
arrow.addActionListener(new XSliderActionListener());
window = new XSliderWindow(slider);
add(value);
add(arrow);
}
private class XSliderWindow extends JWindow {
private JSlider jslider = null;
private Thread windowKiller = null;
public XSliderWindow(JSlider jslider) {
super();
this.jslider = jslider;
setSize(105, jslider.getPreferredSize().height+10);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createRaisedBevelBorder());
panel.setLayout(new BorderLayout());
panel.add(BorderLayout.CENTER, jslider);
windowKiller = new WindowKiller(this);
getContentPane().add(BorderLayout.CENTER, panel);
jslider.addMouseListener(new MouseAdapter() {
public void mouseExited(MouseEvent e) {
if(!windowKiller.isAlive()) {
windowKiller = new WindowKiller(XSliderWindow.this);
windowKiller.start();
}
}
public void mouseEntered(MouseEvent e) {
if(windowKiller.isAlive())
windowKiller.interrupt();
}
});
}
@Override
public void setVisible(boolean visible) {
setLocation(value.getLocationOnScreen().x,
value.getLocationOnScreen().y + value.getPreferredSize().height+2);
super.setVisible(visible);
if(visible) {
windowKiller = new WindowKiller(this);
windowKiller.start();
} else {
if(windowKiller.isAlive())
windowKiller.interrupt();
}
}
private class WindowKiller extends Thread {
public final static long DELAY = 5000;
private JWindow window = null;
public WindowKiller(JWindow window) {
this.window = window;
}
public void run() {
try {
sleep(DELAY);
window.setVisible(false);
}catch(InterruptedException ie) {
return ;
}
}
}//koniec DialogKiller
}//koniec XSliderWindow
public class XSliderActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equalsIgnoreCase("showDialog")) {
window.setVisible(!window.isVisible());
}
}
}//koniec XSliderActionListener
private class XSliderChangeListener implements ChangeListener {
public void stateChanged(ChangeEvent e) {
value.setText(""+slider.getValue());
}
}//koniec XSliderChangeListener
}