source: src/main/java/genius/gui/panels/SpinnerPanel.java

Last change on this file was 144, checked in by Wouter Pasman, 6 years ago

#54 set initial state properly

File size: 1.1 KB
Line 
1package genius.gui.panels;
2
3import java.awt.BorderLayout;
4import java.awt.Component;
5import java.awt.Dimension;
6
7import javax.swing.JLabel;
8import javax.swing.JPanel;
9import javax.swing.JSpinner;
10
11/**
12 * Spinner but with text label.
13 *
14 */
15@SuppressWarnings("serial")
16public class SpinnerPanel extends JPanel {
17
18 private final JSpinner spinner;
19 private final NumberModel model;
20 private final JLabel label;
21
22 public SpinnerPanel(final String labeltext, final NumberModel model) {
23 this.model = model;
24 setLayout(new BorderLayout());
25 label = new JLabel(labeltext);
26 add(label, BorderLayout.WEST);
27 label.setPreferredSize(new Dimension(120, 10));
28
29 spinner = new JSpinner(model.getSpinnerModel());
30 spinner.setMaximumSize(new Dimension(300, 30));
31 add(spinner, BorderLayout.CENTER);
32 // aligns the RIGHT side of the panel with the center of the parent.
33 // This limits the total width
34 setAlignmentX(Component.RIGHT_ALIGNMENT);
35 setMaximumSize(new Dimension(3000000, 30));
36
37 model.addListener(data -> enable1());
38 enable1();
39
40 }
41
42 private void enable1() {
43 boolean enabled = !model.isLocked();
44 spinner.setEnabled(enabled);
45 label.setEnabled(enabled);
46 }
47}
Note: See TracBrowser for help on using the repository browser.