Java Reference
In-Depth Information
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Text Slider");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final TextSlider ts = new TextSlider();
ts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Text: " + ts.getText());
}
});
frame.add(ts, BorderLayout.NORTH);
frame.setSize(300, 100);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Normally, the JTextField has no associated scrollbar. In fact, most look and feel types
don't offer it as an alternative. However, if this component is something you want to incorporate,
you can reuse it in your own applications. Plenty of accessor methods should make reuse
simpler, and you can avoid needing to access the internal pieces directly.
Summary
In this chapter, you've learned how to use Swing's JScrollBar , JSlider , and JProgressBar
components. You saw how each uses the BoundedRangeModel interface to control the internal
data necessary to operate the component, and how the DefaultBoundedRangeModel class offers
a default implementation of this data model.
Now that you know how to use the various bounded range components, you can move on
to Chapter 13, which looks at the controls that offer data selection: JList and JComboBox .
Search WWH ::




Custom Search