Previous lesson: 14.17 JOptionPaneCourse contents Access modifiers and visibility Access modifiers enable you to protect and control parts of your application from inappropriate use by other parts or other applications. A singleton class is one where no more than one instance of that class can exist. In this section you will learn: An ov...
Previous lesson: 14.16 JDialogCourse contents JOptionPane The JOptionPane class provides a simple way of displaying standard dialogs that show informational, warning or error messages through its static convenience methods. Change the ShowDialogButtonListener inner class as follows: private class ShowDialogButtonListener implements ActionList...
Previous lesson: 14.15 JTabbedPaneCourse contents JDialog The JDialog class displays a separate window which is "owned" by an application's frame. You can either add your own components to a dialog or use a simple pre-built one through the JOptionPane class. There follows an ActionListener inner class that builds and displays a JDialog consisting o...
Previous lesson: 14.14 JSplitPaneCourse contents JTabbedPane The JTabbedPane class displays separate titled "tabs", each of which allows the user to switch between by clicking on a tab: JPanel panelOne = new JPanel();panelOne.add(new JLabel("This is the first panel"));JPanel panelTwo = new JPanel();panelTwo.add(new JLabel("This is the second ...
Previous lesson: 14.13 JTreeCourse contents JSplitPane The JSplitPane class displays two components next to each other with a user moveable dividing bar between them. Usually, the components on either side of the divider will be panels, each containing one of more other components: // Panel to go on the left or the topJPanel panelOne = new JP...
Previous lesson: 14.12 JTableCourse contents JTree The JTree class displays items which are structured in a hierarchy. Each item is known as a node, and each node can contain other nodes as its "children". Like JList and JTable, the JTree uses an associated model object (a TreeModel) to provide its data. However, in many cases it is easier to...
Previous lesson: 14.11 JListCourse contents JTable Whereas the JList class displayed a list of items in a single column, the JTable class is capable of showing items that each have several columns. You need to attach a TableModel object (which references the item data) to the JTable. The most common way of doing this is to subclass the Abstra...
Previous lesson: 14.10 JSpinnerCourse contents JList The JList class displays a selection of a number of items, from which one or more may be selected. It is possible to pass an array of objects into the JList constructor, and it is usual to nest the list inside a JScrollPane: String[] options = {"Red", "Green", "Blue"};JList list = ne...
Previous lesson: 14.9 JSliderCourse contents JSpinner The JSpinner class enables the user to "spin" through a range of items using small up and down arrow buttons: JSpinner spinner = new JSpinner();panel.add(spinner); By default, the spinner allows the spinning through an unbounded range of integer values, defaulting to zero. You can use the ...
Previous lesson: 14.8 JComboBoxCourse contents JSlider The JSlider class allows the user to select a value, from within a range of values, by moving a sliding knob: JSlider slider = new JSlider();panel.add(slider); By default, the allowable range of values is from 0 to 100, with the knob pre-selected at 50. The default slider will look like t...