List of usage examples for javax.swing JComboBox getSelectedItem
public Object getSelectedItem()
From source file:co.edu.unal.pos.gui.PosHadoopJFrame.java
private IntegerFilterOperator getIntegerFilterOperator(JComboBox jComboBox) { String selectedOperator = (String) jComboBox.getSelectedItem(); return IntegerFilterOperator.getFromString(selectedOperator); }
From source file:br.com.criativasoft.opendevice.samples.ui.SimpleChart.java
public SimpleChart(final String title, final StreamConnection connection) { super(title); dataset = new DynamicTimeSeriesCollection(SERIES, COUNT, new Second()); dataset.setTimeBase(new Second(0, 0, 0, 1, 1, Calendar.getInstance().get(Calendar.YEAR))); // Init.//ww w.j av a 2s . com // for (int i = 0; i < SERIES; i++){ // dataset.addSeries(new float[]{0}, i, "Serie " + (i+1)); // } dataset.addSeries(new float[] { 0, 0, 0 }, 0, "Raw"); dataset.addSeries(new float[] { 0, 0, 0 }, 1, "Software"); dataset.addSeries(new float[] { 0, 0, 0 }, 2, "Hardware"); this.connection = connection; // connection.setStreamReader(new FixedStreamReader(1)); JFreeChart chart = createChart(dataset); final JButton run = new JButton(START); run.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); JButton source = (JButton) e.getSource(); try { if (cmd.equals(START)) { connection.addListener(SimpleChart.this); if (!connection.isConnected()) connection.connect(); source.setText(STOP); source.setActionCommand(STOP); } else { connection.removeListener(SimpleChart.this); source.setText(START); source.setActionCommand(START); } } catch (ConnectionException e1) { e1.printStackTrace(); } } }); final JComboBox combo = new JComboBox(); if (connection instanceof UsbConnection) { Collection<String> portNames = UsbConnection.listAvailablePortNames(); for (String name : portNames) { combo.addItem(name); } } combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object selectedItem = combo.getSelectedItem(); } }); this.add(new ChartPanel(chart), BorderLayout.CENTER); JPanel btnPanel = new JPanel(new FlowLayout()); btnPanel.add(run); btnPanel.add(combo); this.add(btnPanel, BorderLayout.SOUTH); }
From source file:net.pandoragames.far.ui.swing.dialog.SettingsDialog.java
private void init() { this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS)); this.setResizable(false); JPanel basePanel = new JPanel(); basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS)); basePanel.setBorder(//from ww w. ja v a 2 s . c o m BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); registerCloseWindowKeyListener(basePanel); // sink for error messages MessageLabel errorField = new MessageLabel(); errorField.setMinimumSize(new Dimension(100, swingConfig.getStandardComponentHight())); errorField.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); TwoComponentsPanel lineError = new TwoComponentsPanel(errorField, Box.createRigidArea(new Dimension(1, swingConfig.getStandardComponentHight()))); lineError.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineError); // character set JLabel labelCharset = new JLabel(swingConfig.getLocalizer().localize("label.default-characterset")); labelCharset.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(labelCharset); JComboBox listCharset = new JComboBox(swingConfig.getCharsetList().toArray()); listCharset.setAlignmentX(Component.LEFT_ALIGNMENT); listCharset.setSelectedItem(swingConfig.getDefaultCharset()); listCharset.setEditable(true); listCharset.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); listCharset.addActionListener(new CharacterSetListener(errorField)); listCharset.setEditor(new CharacterSetEditor(errorField)); basePanel.add(listCharset); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // select the group selector JPanel selectorPanel = new JPanel(); selectorPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); selectorPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // linePattern.setAlignmentX( Component.LEFT_ALIGNMENT ); JLabel labelSelector = new JLabel(swingConfig.getLocalizer().localize("label.group-ref-indicator")); selectorPanel.add(labelSelector); JComboBox selectorBox = new JComboBox(FARConfig.GROUPREFINDICATORLIST); selectorBox.setSelectedItem(Character.toString(groupReference)); selectorBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JComboBox cbox = (JComboBox) event.getSource(); String indicator = (String) cbox.getSelectedItem(); groupReference = indicator.charAt(0); } }); selectorPanel.add(selectorBox); basePanel.add(selectorPanel); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // checkbox DO BACKUP JCheckBox doBackupFlag = new JCheckBox(swingConfig.getLocalizer().localize("label.create-backup")); doBackupFlag.setAlignmentX(Component.LEFT_ALIGNMENT); doBackupFlag.setHorizontalTextPosition(SwingConstants.LEADING); doBackupFlag.setSelected(replaceForm.isDoBackup()); doBackupFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { doBackup = ItemEvent.SELECTED == event.getStateChange(); backupFlagEvent = event; } }); basePanel.add(doBackupFlag); JTextField backupDirPathTextField = new JTextField(); backupDirPathTextField.setPreferredSize( new Dimension(SwingConfig.COMPONENT_WIDTH, swingConfig.getStandardComponentHight())); backupDirPathTextField.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); backupDirPathTextField.setText(backupDirectory.getPath()); backupDirPathTextField.setToolTipText(backupDirectory.getPath()); backupDirPathTextField.setEditable(false); JButton openBaseDirFileChooserButton = new JButton(swingConfig.getLocalizer().localize("button.browse")); BrowseButtonListener backupDirButtonListener = new BrowseButtonListener(backupDirPathTextField, new BackUpDirectoryRepository(swingConfig, findForm, replaceForm, errorField), swingConfig.getLocalizer().localize("label.choose-backup-directory")); openBaseDirFileChooserButton.addActionListener(backupDirButtonListener); TwoComponentsPanel lineBaseDir = new TwoComponentsPanel(backupDirPathTextField, openBaseDirFileChooserButton); lineBaseDir.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineBaseDir); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); JPanel fileInfoPanel = new JPanel(); fileInfoPanel .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), swingConfig.getLocalizer().localize("label.default-file-info"))); fileInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.setLayout(new BoxLayout(fileInfoPanel, BoxLayout.Y_AXIS)); JLabel fileInfoLabel = new JLabel(swingConfig.getLocalizer().localize("message.displayed-in-info-column")); fileInfoLabel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.add(fileInfoLabel); fileInfoPanel.add(Box.createHorizontalGlue()); JRadioButton nothingRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.nothing")); nothingRadio.setAlignmentX(Component.LEFT_ALIGNMENT); nothingRadio.setActionCommand(SwingConfig.DefaultFileInfo.NOTHING.name()); nothingRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.NOTHING); fileInfoOptions.add(nothingRadio); fileInfoPanel.add(nothingRadio); JRadioButton readOnlyRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.read-only-warning")); readOnlyRadio.setAlignmentX(Component.LEFT_ALIGNMENT); readOnlyRadio.setActionCommand(SwingConfig.DefaultFileInfo.READONLY.name()); readOnlyRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.READONLY); fileInfoOptions.add(readOnlyRadio); fileInfoPanel.add(readOnlyRadio); JRadioButton sizeRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.filesize")); sizeRadio.setAlignmentX(Component.LEFT_ALIGNMENT); sizeRadio.setActionCommand(SwingConfig.DefaultFileInfo.SIZE.name()); sizeRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.SIZE); fileInfoOptions.add(sizeRadio); fileInfoPanel.add(sizeRadio); JCheckBox showPlainBytesFlag = new JCheckBox( " " + swingConfig.getLocalizer().localize("label.show-plain-bytes")); showPlainBytesFlag.setAlignmentX(Component.LEFT_ALIGNMENT); showPlainBytesFlag.setHorizontalTextPosition(SwingConstants.LEADING); showPlainBytesFlag.setSelected(swingConfig.isShowPlainBytes()); showPlainBytesFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { showBytes = ItemEvent.SELECTED == event.getStateChange(); } }); fileInfoPanel.add(showPlainBytesFlag); JRadioButton lastModifiedRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.last-modified")); lastModifiedRadio.setAlignmentX(Component.LEFT_ALIGNMENT); lastModifiedRadio.setActionCommand(SwingConfig.DefaultFileInfo.LAST_MODIFIED.name()); lastModifiedRadio .setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.LAST_MODIFIED); fileInfoOptions.add(lastModifiedRadio); fileInfoPanel.add(lastModifiedRadio); basePanel.add(fileInfoPanel); // buttons JPanel buttonPannel = new JPanel(); buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT); buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING)); // cancel JButton cancelButton = new JButton(swingConfig.getLocalizer().localize("button.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SettingsDialog.this.dispose(); } }); buttonPannel.add(cancelButton); // save JButton saveButton = new JButton(swingConfig.getLocalizer().localize("button.save")); saveButton.addActionListener(new SaveButtonListener()); buttonPannel.add(saveButton); this.getRootPane().setDefaultButton(saveButton); this.add(basePanel); this.add(buttonPannel); placeOnScreen(swingConfig.getScreenCenter()); }
From source file:projects.hip.exec.HrDiagram.java
/** * Main constructor.//from ww w. ja v a2s . com */ public HrDiagram() { hipStars = HipUtils.loadHipCatalogue(); method = METHOD.NAIVE; fMax = 1.0; final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(2, 2)); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(hrDiagPanel, BorderLayout.WEST); add(dDistPanel, BorderLayout.EAST); add(controls, BorderLayout.SOUTH); }
From source file:edu.ku.brc.specify.datamodel.busrules.PickListBusRules.java
/** * /*from w w w .jav a2s. com*/ */ private void tableSelected(final FormViewObj fvo) { ValComboBox formatterCBX = (ValComboBox) fvo.getControlByName("formatterCBX"); ValComboBox tablesCBX = (ValComboBox) fvo.getControlByName("tablesCBX"); ValComboBox fieldsCBX = (ValComboBox) fvo.getControlByName("fieldsCBX"); fvo.getValidator().setHasChanged(true); tablesCBX.setChanged(true); //int typeIndex = typesCBX.getComboBox().getSelectedIndex(); String noneStr = getResourceString("NONE"); PickList pickList = (PickList) fvo.getDataObj(); if (pickList == null) { return; } JComboBox tableCbx = tablesCBX.getComboBox(); DBTableInfo tblInfo = (DBTableInfo) tableCbx.getSelectedItem(); if (tblInfo != null) { if (tblInfo.getName().equals(noneStr)) { pickList.setTableName(null); pickList.setFieldName(null); pickList.setFormatter(null); } else { pickList.setTableName(tblInfo.getName()); DefaultComboBoxModel fldModel = (DefaultComboBoxModel) fieldsCBX.getComboBox().getModel(); fldModel.removeAllElements(); for (DBFieldInfo fi : tblInfo.getFields()) { if (fi.getDataClass() == String.class) { fldModel.addElement(fi); } } Vector<DataObjSwitchFormatter> list = new Vector<DataObjSwitchFormatter>(); for (DataObjSwitchFormatter fmt : DataObjFieldFormatMgr.getInstance().getFormatters()) { if (fmt.getDataClass() == tblInfo.getClassObj()) { list.add(fmt); } } DefaultComboBoxModel fmtModel = (DefaultComboBoxModel) formatterCBX.getComboBox().getModel(); fmtModel.removeAllElements(); if (list.size() > 0) { Collections.sort(list); for (DataObjSwitchFormatter fmt : list) { fmtModel.addElement(fmt); } formatterCBX.setEnabled(true); } else { formatterCBX.setEnabled(false); } } } else { fieldsCBX.setEnabled(false); } }
From source file:fuel.gui.stats.MotorStatsPanel.java
public MotorStatsPanel(Database database) throws SQLException { this.database = database; controller = new Controller(); JPanel container = new JPanel(new BorderLayout()); //container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JPanel motorSelectionPanel = new JPanel(); motorSelectionPanel.setLayout(new BoxLayout(motorSelectionPanel, BoxLayout.X_AXIS)); motorSpecsPanel = new JPanel(new GridLayout(2, 3)); motorSpecsPanel.setBorder(BorderFactory.createTitledBorder("Specs")); graphContainer = new JPanel(); graphContainer.setLayout(new BoxLayout(graphContainer, BoxLayout.Y_AXIS)); JComboBox motorSelector = new JComboBox(database.getMotorcycles().toArray()); motorSelector.setActionCommand("SELECTMOTOR"); motorSelector.addActionListener(controller); motorSelectionPanel.add(motorSelector); //motorSelector.setSelectedIndex(0); motorSelectionPanel.add(motorSpecsPanel); refreshMotorSpecs((Motorcycle) motorSelector.getSelectedItem()); container.add(motorSelectionPanel, BorderLayout.NORTH); JScrollPane scroll = new JScrollPane(graphContainer); scroll.getHorizontalScrollBar().setUnitIncrement(10); scroll.getVerticalScrollBar().setUnitIncrement(10); container.add(scroll, BorderLayout.CENTER); refreshGraphs((Motorcycle) motorSelector.getSelectedItem()); setLayout(new BorderLayout()); add(container);//from ww w. j av a 2 s . c o m setVisible(true); }
From source file:com.eviware.soapui.impl.rest.panels.mock.RestMockResponseDesktopPanel.java
private JComboBox createStatusCodeCombo() { ComboBoxModel httpStatusCodeComboBoxModel = new HttpStatusCodeComboBoxModel(); final JComboBox statusCodeCombo = new JComboBox(httpStatusCodeComboBoxModel); statusCodeCombo.setSelectedItem(CompleteHttpStatus.from(getModelItem().getResponseHttpStatus())); statusCodeCombo.setToolTipText("Set desired HTTP status code"); statusCodeCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { getModelItem().setResponseHttpStatus( ((CompleteHttpStatus) statusCodeCombo.getSelectedItem()).getStatusCode()); }//w w w. j a va 2s. com }); return statusCodeCombo; }
From source file:com.game.ui.views.CharacterEditor.java
@Override public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equalsIgnoreCase("dropDown")) { JComboBox cbox = (JComboBox) ae.getSource(); String nameTxt = cbox.getSelectedItem().toString(); character = charMap.get(nameTxt); name.setText(nameTxt);// w ww . j ava2 s.c om imgPath.setText(character.getImagePath()); hitPoints.setText("" + character.getHealth()); level.setText("" + character.getLevel()); Inventory inv = character.getInventory(); if (inv != null) { Weapon dummy = inv.getEquippedWeapon(); if (dummy != null) { meleeWeapon.setSelectedItem(dummy.getName()); } for (Item item : inv.getItems()) { if (item instanceof Weapon) { Weapon wpn = (Weapon) item; if (wpn.getWeaponType().equalsIgnoreCase(Configuration.weaponTypes[1])) { { rangedWeapon.setSelectedItem(wpn.getName()); break; } } } } Armour chest = inv.getChest(); Armour shld = inv.getShield(); if (chest != null) { armour.setSelectedItem(chest.getName()); } if (shld != null) { shield.setSelectedItem(shld.getName()); } } ta.setText(""); ta.append("Strength : " + character.getStrength()); ta.append("\nDexterity : " + character.getDexterity()); ta.append("\nConstitution : " + character.getConstitution()); ta.append("\nIntelligence : " + character.getIntelligence()); ta.append("\nCharisma: " + character.getCharisma()); ta.append("\nWisdom : " + character.getWisdom()); ta.append("\nType :" + character.getType()); ta.append("\nStrength Modifier :" + character.getStrengthModifier()); ta.append("\nConstitution Modifier :" + character.getConstitutionModifier()); ta.append("\nDexterity Modifier :" + character.getDexterityModifier()); validationMess.setText(""); // validationMess.setvi builder = new CharacterBuilder(character); generated = true; this.revalidate(); } else { String nameTxt = name.getText(); String img = imgPath.getText(); String lvl = level.getText(); String melWpn = meleeWeapon.getSelectedItem().toString(); String health = hitPoints.getText(); String rngdWpn = rangedWeapon.getSelectedItem().toString(); String armr = armour.getSelectedItem().toString(); String shld = shield.getSelectedItem().toString(); if (StringUtils.isNotBlank(nameTxt) && StringUtils.isNotBlank(img) && StringUtils.isNotBlank(lvl) && StringUtils.isNotBlank(melWpn) && StringUtils.isNotBlank(rngdWpn) && StringUtils.isNotBlank(armr) && StringUtils.isNotBlank(shld) && StringUtils.isNotBlank(health)) { if (generated) { if (isEnemy) { persistEnemyWrapper(nameTxt, img, lvl, melWpn, rngdWpn, armr, shld, health); } else { persistPlayerWrapper(nameTxt, img, lvl, melWpn, rngdWpn, armr, shld, health); } } else { validationMess.setText("Pls hit generate button before you submit.."); } } else { validationMess.setText("All the fields are mandatory.."); } validationMess.setVisible(true); this.revalidate(); } }
From source file:EHRAppointment.ChartPanelDraw.java
private JComboBox createDate() { // to change the vertical and horizontal data final JComboBox date = new JComboBox(); final String[] dateCmds = { "Horizontal Dates", "Vertical Dates" }; date.setModel(new DefaultComboBoxModel(dateCmds)); date.addActionListener(new ActionListener() { @Override/* ww w. j a v a 2 s. co m*/ public void actionPerformed(ActionEvent e) { JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); DateAxis domain = (DateAxis) plot.getDomainAxis(); if (dateCmds[0].equals(date.getSelectedItem())) { domain.setVerticalTickLabels(false); } else { domain.setVerticalTickLabels(true); } } }); return date; }
From source file:projects.upc.exec.HrDiagram.java
/** * Main constructor./* w ww .j a v a 2s . c o m*/ */ public HrDiagram() { List<UpcStar> upcStars = UpcUtils.loadUpcCatalogue(); List<UpcStar> hipStars = UpcUtils.getHipparcosSubset(upcStars); List<UpcStar> unmatchedStars = UpcUtils.getUnmatchedSubset(upcStars); upcStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(upcStars); hipStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(hipStars); unmatchedStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(unmatchedStars); logger.info("Loaded " + upcStarCrossMatches.size() + " UpcStars with SSA cross matches"); logger.info("Loaded " + hipStarCrossMatches.size() + " UpcStars with Hipparcos and SSA cross matches"); logger.info("Loaded " + unmatchedStarCrossMatches.size() + " UpcStars with no parallax cross-match, and with SSA cross matches"); starsToPlot = upcStarCrossMatches; useHip = false; method = METHOD.NAIVE; fMax = 1.0; final JCheckBox plotAllCheckBox = new JCheckBox("Plot all UPC stars: ", true); plotAllCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotAllCheckBox.isSelected()) { starsToPlot = upcStarCrossMatches; updateChart(); } } }); final JCheckBox plotHipCheckBox = new JCheckBox("Plot Hipparcos stars only: ", false); plotHipCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotHipCheckBox.isSelected()) { starsToPlot = hipStarCrossMatches; updateChart(); } } }); final JCheckBox plotUnmatchedCheckBox = new JCheckBox("Plot all stars with no external match: ", false); plotUnmatchedCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (plotUnmatchedCheckBox.isSelected()) { starsToPlot = unmatchedStarCrossMatches; updateChart(); } } }); final ButtonGroup bg = new ButtonGroup(); bg.add(plotHipCheckBox); bg.add(plotAllCheckBox); bg.add(plotUnmatchedCheckBox); JCheckBox useHipCheckBox = new JCheckBox("Use Hipparcos parallaxes when available", useHip); useHipCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { useHip = !useHip; updateChart(); } }); final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(3, 3)); controls.add(plotAllCheckBox); controls.add(plotHipCheckBox); controls.add(plotUnmatchedCheckBox); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(useHipCheckBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); add(controls, BorderLayout.SOUTH); }