import java.awt.*;
public class TextSlider {
public static void main(String args[]) {
JFrame frame = new JFrame("Text Slider");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField textField = new JTextField();
JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
BoundedRangeModel brm = textField.getHorizontalVisibility();
scrollBar.setModel(brm);
panel.add(textField);
panel.add(scrollBar);
final TextSlider ts = new TextSlider();
textField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Text: " + textField.getText());
}
});
frame.add(panel, BorderLayout.NORTH);
frame.setSize(300, 100);
frame.setVisible(true);
}
}
OUTPUT :
public class TextSlider {
public static void main(String args[]) {
JFrame frame = new JFrame("Text Slider");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField textField = new JTextField();
JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
BoundedRangeModel brm = textField.getHorizontalVisibility();
scrollBar.setModel(brm);
panel.add(textField);
panel.add(scrollBar);
final TextSlider ts = new TextSlider();
textField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Text: " + textField.getText());
}
});
frame.add(panel, BorderLayout.NORTH);
frame.setSize(300, 100);
frame.setVisible(true);
}
}
OUTPUT :
No comments:
Post a Comment