List of usage examples for javax.swing JSpinner addChangeListener
public void addChangeListener(ChangeListener listener)
From source file:Main.java
public static void main(String[] argv) throws Exception { JSpinner spinner = new JSpinner(); spinner.addChangeListener(new SpinnerListener()); spinner.setValue(new Integer(100)); }
From source file:AddingChangeListenerToJSpinner.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JSpinner dateSpinner = new JSpinner(); dateSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { SpinnerModel dateModel = dateSpinner.getModel(); System.out.println(dateModel.getValue()); }//from w ww . ja va 2s . com }); frame.add(dateSpinner, "North"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }/*w ww . j ava2s . co m*/ }; SpinnerModel model3 = new SpinnerNumberModel(); JSpinner spinner3 = new JSpinner(model3); spinner3.addChangeListener(listener); frame.add(spinner3, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }/*from w w w .jav a2s . co m*/ }; SpinnerModel model3 = new SpinnerNumberModel(); JSpinner spinner3 = new JSpinner(model3); spinner3.addChangeListener(listener); ChangeListener[] changeListeners = spinner3.getChangeListeners(); frame.add(spinner3, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH); String days[] = symbols.getWeekdays(); SpinnerModel model1 = new SpinnerListModel(days); JSpinner spinner1 = new JSpinner(model1); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }/* ww w .j av a 2s . c o m*/ }; spinner1.addChangeListener(listener); JLabel label1 = new JLabel("French Days/List"); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(label1, BorderLayout.WEST); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.NORTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public void makeUI() { String[] zones = { "Asia/Tokyo", "Asia/Hong_Kong", "Asia/Calcutta", "Europe/Paris", "Europe/London", "America/New_York", "America/Los_Angeles" }; JLabel[] labels = new JLabel[zones.length]; SimpleDateFormat[] formats = new SimpleDateFormat[zones.length]; JFrame frame = new JFrame(); Calendar cal = Calendar.getInstance(); Date date = cal.getTime();/*from ww w . ja v a2s.c o m*/ SpinnerDateModel model = new SpinnerDateModel(); model.setValue(date); JSpinner spinner = new JSpinner(model); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Date date = (Date) ((JSpinner) e.getSource()).getValue(); for (int i = 0; i < labels.length; i++) { labels[i].setText(formats[i].format(date)); } } }); SimpleDateFormat format = ((JSpinner.DateEditor) spinner.getEditor()).getFormat(); format.setTimeZone(TimeZone.getTimeZone(zones[0])); format.applyPattern("yyyy-MM-dd HH:mm:ss"); JPanel panel = new JPanel(new GridLayout(zones.length, 2, 10, 10)); for (int i = 0; i < zones.length; i++) { formats[i] = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); formats[i].setTimeZone(TimeZone.getTimeZone(zones[i])); JLabel label = new JLabel(zones[i]); labels[i] = new JLabel(formats[i].format(date)); panel.add(label); panel.add(labels[i]); } frame.setLayout(new BorderLayout()); frame.add(spinner, BorderLayout.NORTH); frame.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:biomine.bmvis2.pipeline.KMedoidsHighlight.java
@Override public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { Box ret = new Box(BoxLayout.X_AXIS); ret.add(new JLabel("k:")); final JSpinner spin = new JSpinner(new SpinnerNumberModel(3, 1, 1000, 1)); spin.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { setK(((Number) spin.getValue()).intValue()); v.settingsChanged(false);/*from ww w . java2s .co m*/ } }); ret.add(spin); final JCheckBox showClustersBox = new JCheckBox("Color clusters"); ret.add(showClustersBox); showClustersBox.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { showClusters = showClustersBox.isSelected(); v.settingsChanged(false); } }); return ret; }
From source file:GrayModel.java
public GrayEditor(JSpinner spinner) { setOpaque(true);/* w w w .ja v a 2s . co m*/ // Get info from the model. GrayModel myModel = (GrayModel) (spinner.getModel()); setBackground(myModel.getColor()); spinner.addChangeListener(this); // Set tool tip text. updateToolTipText(spinner); // Set size info. Dimension size = new Dimension(60, 15); setMinimumSize(size); setPreferredSize(size); }
From source file:coreferenceresolver.gui.MarkupGUI.java
private JScrollPane newMarkupPanel(NounPhrase np, ReviewElement reviewElement) { //MODEL// w w w .j a va2s . c om Element element = new Element(); //Newly added ScrollablePanel markupPanel = new ScrollablePanel(); markupPanel.setLayout(new BoxLayout(markupPanel, BoxLayout.X_AXIS)); markupPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT); JTextArea npContentTxtArea = new JTextArea(); npContentTxtArea.setEditable(false); npContentTxtArea.setText(((MarkupNounPhrase) np).content); markupPanel.add(npContentTxtArea); //REF SpinnerModel refSpinnerModel = new SpinnerNumberModel(np.getChainId(), -1, COLORS.length - 1, 1); JSpinner refSpinner = new JSpinner(refSpinnerModel); refSpinner.setValue(np.getChainId()); refSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { np.setChainId((int) refSpinner.getValue()); try { rePaint(reviewElements.get(np.getReviewId()), np); } catch (BadLocationException ex) { Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex); } } }); element.refSpinner = refSpinner; //TYPE String[] typeValues = { "Object", "Other", "Candidate", "Attribute" }; SpinnerModel typeSpinnerModel = new SpinnerListModel(typeValues); JSpinner typeSpinner = new JSpinner(typeSpinnerModel); typeSpinner.setValue(typeValues[np.getType()]); element.typeSpinner = typeSpinner; //REF + TYPE ScrollablePanel spinners = new ScrollablePanel(); spinners.setLayout(new BoxLayout(spinners, BoxLayout.X_AXIS)); spinners.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT); spinners.add(refSpinner); spinners.add(typeSpinner); markupPanel.add(spinners); reviewElement.addElement(element); JScrollPane scrollMarkupPanel = new JScrollPane(markupPanel); return scrollMarkupPanel; }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.controls.ClusteringControl.java
public void init() { maxCluster = state.growingLayer.getXSize() * state.growingLayer.getYSize(); spinnerNoCluster = new JSpinner(new SpinnerNumberModel(1, 1, maxCluster, 1)); spinnerNoCluster.addChangeListener(new ChangeListener() { @Override//from w ww. j a va 2s .c om public void stateChanged(ChangeEvent e) { numClusters = (Integer) ((JSpinner) e.getSource()).getValue(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { st = m.get(numClusters).sticky; } else { st = false; } sticky.setSelected(st); redrawClustering(); } }); JPanel clusterPanel = UiUtils.makeBorderedPanel(new FlowLayout(FlowLayout.LEFT, 10, 0), "Clusters"); sticky.setToolTipText( "Marks this number of clusters as sticky for a certain leve; the next set of clusters will have a smaller boundary"); sticky.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { st = sticky.isSelected(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { ClusterElementsStorage c = m.get(numClusters); c.sticky = st; // System.out.println("test"); // ((ClusterElementsStorageNode)m.get(numClusters)).sticky = st; redrawClustering(); } } }); colorCluster = new JCheckBox("colour", state.colorClusters); colorCluster.setToolTipText("Fill the clusters in colours"); colorCluster.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.colorClusters = colorCluster.isSelected(); // TODO: Palette anzeigen (?) redrawClustering(); } }); UiUtils.fillPanel(clusterPanel, new JLabel("#"), spinnerNoCluster, sticky, colorCluster); getContentPane().add(clusterPanel, c.nextRow()); dendogramPanel = UiUtils.makeBorderedPanel(new GridLayout(0, 1), "Dendogram"); getContentPane().add(dendogramPanel, c.nextRow()); JPanel numLabelPanel = UiUtils.makeBorderedPanel(new GridBagLayout(), "Labels"); GridBagConstraintsIFS gcLabels = new GridBagConstraintsIFS(); labelSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1)); labelSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { numLabels = (Integer) ((JSpinner) e.getSource()).getValue(); state.clusterWithLabels = numLabels; redrawClustering(); } }); this.showValues = new JCheckBox("values", state.labelsWithValues); this.showValues.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.labelsWithValues = showValues.isSelected(); redrawClustering(); } }); int start = new Double((1 - state.clusterByValue) * 100).intValue(); valueQe = new JSlider(0, 100, start); valueQe.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int byValue = ((JSlider) e.getSource()).getValue(); state.clusterByValue = 1 - byValue / 100; redrawClustering(); } }); numLabelPanel.add(new JLabel("# Labels"), gcLabels); numLabelPanel.add(labelSpinner, gcLabels.nextCol()); numLabelPanel.add(showValues, gcLabels.nextCol()); numLabelPanel.add(valueQe, gcLabels.nextRow().setGridWidth(3).setFill(GridBagConstraints.HORIZONTAL)); getContentPane().add(numLabelPanel, c.nextRow()); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(0, new JLabel("by Value")); labelTable.put(100, new JLabel("by Qe")); valueQe.setToolTipText("Method how to select representative labels - by QE, or the attribute values"); valueQe.setLabelTable(labelTable); valueQe.setPaintLabels(true); final JComboBox initialisationBox = new JComboBox(KMeans.InitType.values()); initialisationBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object o = mapPane.getMap().getClusteringTreeBuilder(); if (o instanceof KMeansTreeBuilder) { ((KMeansTreeBuilder) o).reInit((KMeans.InitType) initialisationBox.getSelectedItem()); // FIXME: is this call needed? mapPane.getMap().getCurrentClusteringTree().getAllClusteringElements(); redrawClustering(); } } }); getContentPane().add(UiUtils.fillPanel(kmeansInitialisationPanel, new JLabel("k-Means initialisation"), initialisationBox), c.nextRow()); JPanel borderPanel = new TitledCollapsiblePanel("Border", new GridLayout(1, 4), true); JSpinner borderSpinner = new JSpinner( new SpinnerNumberModel(ClusteringTree.INITIAL_BORDER_WIDTH_MAGNIFICATION_FACTOR, 0.1, 5, 0.1)); borderSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { state.clusterBorderWidthMagnificationFactor = ((Double) ((JSpinner) e.getSource()).getValue()) .floatValue(); redrawClustering(); } }); borderPanel.add(new JLabel("width")); borderPanel.add(borderSpinner); borderPanel.add(new JLabel("colour")); buttonColour = new JButton(""); buttonColour.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new ClusterBoderColorChooser(state.parentFrame, state.clusterBorderColour, ClusteringControl.this); } }); buttonColour.setBackground(state.clusterBorderColour); borderPanel.add(buttonColour); getContentPane().add(borderPanel, c.nextRow()); JPanel evaluationPanel = new TitledCollapsiblePanel("Cluster Evaluation", new GridLayout(3, 2), true); evaluationPanel.add(new JLabel("quality measure")); qualityMeasureButton = new JButton(); qualityMeasureButton.setText("ent/pur calc"); qualityMeasureButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("doing entropy here"); ClusteringTree clusteringTree = state.mapPNode.getClusteringTree(); if (clusteringTree == null) { // we have not clustered yet return; } // System.out.println(clusteringTree.getChildrenCount()); // FIXME put this in a method and call it on numcluster.change() SOMLibClassInformation classInfo = state.inputDataObjects.getClassInfo(); ArrayList<ClusterNode> clusters = clusteringTree.getNodesAtLevel(numClusters); System.out.println(clusters.size()); // EntropyMeasure.computeEntropy(clusters, classInfo); EntropyAndPurityCalculator eapc = new EntropyAndPurityCalculator(clusters, classInfo); // FIXME round first entropyLabel.setText(String.valueOf(eapc.getEntropy())); purityLabel.setText(String.valueOf(eapc.getPurity())); } }); evaluationPanel.add(qualityMeasureButton); GridBagConstraintsIFS gcEval = new GridBagConstraintsIFS(); evaluationPanel.add(new JLabel("entropy"), gcEval); evaluationPanel.add(new JLabel("purity"), gcEval.nextCol()); entropyLabel = new JLabel("n/a"); purityLabel = new JLabel("n/a"); evaluationPanel.add(entropyLabel, gcEval.nextRow()); evaluationPanel.add(purityLabel, gcEval.nextCol()); getContentPane().add(evaluationPanel, c.nextRow()); JPanel panelButtons = new JPanel(new GridLayout(1, 4)); JButton saveButton = new JButton("Save"); saveButton.setFont(smallFont); saveButton.setMargin(SMALL_INSETS); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser; if (state.fileChooser.getSelectedFile() != null) { fileChooser = new JFileChooser(state.fileChooser.getSelectedFile().getPath()); } else { fileChooser = new JFileChooser(); } fileChooser.addChoosableFileFilter(clusteringFilter); fileChooser.addChoosableFileFilter(xmlFilter); File filePath = ExportUtils.getFilePath(ClusteringControl.this, fileChooser, "Save Clustering and Labels"); if (filePath != null) { if (xmlFilter.accept(filePath)) { LabelXmlUtils.saveLabelsToFile(state.mapPNode, filePath); } else { try { FileOutputStream fos = new FileOutputStream(filePath); GZIPOutputStream gzipOs = new GZIPOutputStream(fos); PObjectOutputStream oos = new PObjectOutputStream(gzipOs); oos.writeObjectTree(mapPane.getMap().getCurrentClusteringTree()); oos.writeObjectTree(mapPane.getMap().getManualLabels()); oos.writeInt(state.clusterWithLabels); oos.writeBoolean(state.labelsWithValues); oos.writeDouble(state.clusterByValue); oos.writeObject(spinnerNoCluster.getValue()); oos.close(); } catch (Exception ex) { ex.printStackTrace(); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(saveButton); JButton loadButton = new JButton("Load"); loadButton.setFont(smallFont); loadButton.setMargin(SMALL_INSETS); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = getFileChooser(); fileChooser.setName("Open Clustering"); fileChooser.addChoosableFileFilter(xmlFilter); fileChooser.addChoosableFileFilter(clusteringFilter); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Open"); if (returnVal == JFileChooser.APPROVE_OPTION) { File filePath = fileChooser.getSelectedFile(); if (xmlFilter.accept(filePath)) { PNode restoredLabels = null; try { restoredLabels = LabelXmlUtils.restoreLabelsFromFile(fileChooser.getSelectedFile()); PNode manual = state.mapPNode.getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = restoredLabels.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } manual.addChildren(tmp); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Successfully loaded cluster labels."); } catch (Exception e1) { e1.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading cluster labels: " + e1.getMessage()); } } else { try { FileInputStream fis = new FileInputStream(filePath); GZIPInputStream gzipIs = new GZIPInputStream(fis); ObjectInputStream ois = new ObjectInputStream(gzipIs); ClusteringTree tree = (ClusteringTree) ois.readObject(); PNode manual = (PNode) ois.readObject(); PNode all = mapPane.getMap().getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = manual.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } all.addChildren(tmp); state.clusterWithLabels = ois.readInt(); labelSpinner.setValue(state.clusterWithLabels); state.labelsWithValues = ois.readBoolean(); showValues.setSelected(state.labelsWithValues); state.clusterByValue = ois.readDouble(); valueQe.setValue(new Double((1 - state.clusterByValue) * 100).intValue()); mapPane.getMap().buildTree(tree); spinnerNoCluster.setValue(ois.readObject()); ois.close(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Successfully loaded clustering."); } catch (Exception ex) { ex.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading clustering: " + ex.getMessage()); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(loadButton); JButton exportImages = new JButton("Export"); exportImages.setFont(smallFont); exportImages.setMargin(SMALL_INSETS); exportImages.setToolTipText("Export labels as images (not yet working)"); exportImages.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); if (CommonSOMViewerStateData.fileNamePrefix != null && !CommonSOMViewerStateData.fileNamePrefix.equals("")) { fileChooser.setCurrentDirectory(new File(CommonSOMViewerStateData.fileNamePrefix)); } else { fileChooser.setCurrentDirectory(state.getFileChooser().getCurrentDirectory()); } fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.getSelectedFile() != null) { // reusing the dialog fileChooser.setSelectedFile(null); } fileChooser.setName("Choose path"); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Choose path"); if (returnVal == JFileChooser.APPROVE_OPTION) { // save images String path = fileChooser.getSelectedFile().getAbsolutePath(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing label images to " + path); } } }); panelButtons.add(exportImages); JButton deleteManual = new JButton("Delete"); deleteManual.setFont(smallFont); deleteManual.setMargin(SMALL_INSETS); deleteManual.setToolTipText("Delete manually added labels."); deleteManual.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.mapPNode.getManualLabels().removeAllChildren(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Manual Labels deleted."); } }); panelButtons.add(deleteManual); c.anchor = GridBagConstraints.NORTH; this.getContentPane().add(panelButtons, c.nextRow()); this.setVisible(true); }