JComboBox combo = new JComboBox(items); JTextField field1 = new JTextField("1234.56"); JTextField field2 = new JTextField("9876.54"); JPanel panel = new JPanel(new GridLayout(0, 1)); panel.add(combo); panel.add(new JLabel("Field 1:")); panel.add(field1); panel.add(new JLabel("Field 2:")); panel.add(field2); JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { System.out.println(combo.getSelectedItem() + " " + field1.getText() + " " + field2.getText());
reloadFileButton.setText("Reload File"); final JComboBox<ParseMode> modesCombobox = new JComboBox<>(ParseMode.values()); modesCombobox.setSelectedIndex(0); modesCombobox.addActionListener(event -> { model.setParseMode((ParseMode) modesCombobox.getSelectedItem()); reloadAction.actionPerformed(null); });
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); contentPane.add(scrollPane); String colour = (String) cbox.getSelectedItem(); try frame.add(remHighButton, BorderLayout.PAGE_START); frame.add(contentPane, BorderLayout.CENTER); frame.add(button, BorderLayout.PAGE_END); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); cbox = new JComboBox(colourNames); panel.add(colourLabel);
JFrame f = new JFrame(title); f.setTitle(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new BorderLayout(0, 5)); f.add(chartPanel, BorderLayout.CENTER); chartPanel.setMouseWheelEnabled(true); chartPanel.setHorizontalAxisTrace(true); final JComboBox trace = new JComboBox(); final String[] traceCmds = {"Enable Trace", "Disable Trace"}; trace.setModel(new DefaultComboBoxModel(traceCmds)); if (traceCmds[0].equals(trace.getSelectedItem())) { chartPanel.setHorizontalAxisTrace(true); chartPanel.setVerticalAxisTrace(true); final JComboBox date = new JComboBox(); final String[] dateCmds = {"Horizontal Dates", "Vertical Dates"}; date.setModel(new DefaultComboBoxModel(dateCmds)); XYPlot plot = (XYPlot) chart.getPlot(); DateAxis domain = (DateAxis) plot.getDomainAxis(); if (dateCmds[0].equals(date.getSelectedItem())) { domain.setVerticalTickLabels(false); } else {
@Override public void actionPerformed(ActionEvent e) { List<Employee> employeeList = nurseRosteringPanel.getSolution().getEmployeeList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox employeeListField = new JComboBox( employeeList.toArray(new Object[employeeList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(employeeListField); employeeListField.setSelectedItem(shiftAssignment.getEmployee()); int result = JOptionPane.showConfirmDialog(EmployeePanel.this.getRootPane(), employeeListField, "Select employee", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { Employee toEmployee = (Employee) employeeListField.getSelectedItem(); nurseRosteringPanel.moveShiftAssignmentToEmployee(shiftAssignment, toEmployee); } }
configUrlFileChooserButton = new JButton(rb.getString("download.url.list")); configLogLevelCombobox = new JComboBox<>(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"}); configSelectLangComboBox = new JComboBox<>(supportedLanges); configSelectLangComboBox.setSelectedItem(rb.getLocale().toString()); configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug")); setLogLevel(configLogLevelCombobox.getSelectedItem().toString()); configSaveDirLabel = new JLabel(); try { gbc.gridy = 0; pane.add(ripPanel, gbc); gbc.gridy = 1; pane.add(statusPanel, gbc); gbc.gridy = 2; pane.add(progressPanel, gbc); gbc.gridy = 3; pane.add(optionsPanel, gbc); gbc.weighty = 1;
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); f.add(new ObserverPanel()); f.pack(); f.setLocationByPlatform(true); f.setVisible(true); this.setBorder(BorderFactory.createTitledBorder("ObserverPanel")); JPanel panel = new JPanel(new GridLayout(0, 1)); panel.add(title); panel.add(label); this.add(panel); ObservedPanel observed = new ObservedPanel(); "Alpher", "Bethe", "Gamow", "Dirac", "Einstein" }; private JComboBox combo = new JComboBox(items); private String oldValue; String newValue = (String) combo.getSelectedItem(); firePropertyChange(PHYSICIST, oldValue, newValue); oldValue = newValue;
@Override public void actionPerformed(ActionEvent e) { JPanel listFieldsPanel = new JPanel(new GridLayout(1, 2)); listFieldsPanel.add(new JLabel("Computer:")); List<CloudComputer> computerList = getSolution().getComputerList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox computerListField = new JComboBox( computerList.toArray(new Object[computerList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(computerListField); computerListField.setSelectedItem(process.getComputer()); listFieldsPanel.add(computerListField); int result = JOptionPane.showConfirmDialog(CloudBalancingPanel.this.getRootPane(), listFieldsPanel, "Select computer", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { CloudComputer toComputer = (CloudComputer) computerListField.getSelectedItem(); if (process.getComputer() != toComputer) { solutionBusiness.doChangeMove(process, "computer", toComputer); } solverAndPersistenceFrame.resetScreen(); } }
final JComboBox combo = new JComboBox(); combo.addItem("Fast"); combo.addItem("Slow"); if ("Fast".equals(combo.getSelectedItem())) { timer.setDelay(FAST); } else { btnPanel.add(run); btnPanel.add(combo); this.add(btnPanel, BorderLayout.SOUTH);
private static final JComboBox combo = new JComboBox(); private final String name; this.setPreferredSize(new Dimension(320, 240)); this.setBackground(new Color(random.nextInt())); this.add(new JLabel(name)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for (int i = 1; i < 9; i++) { CardPanel p = new CardPanel("Panel " + String.valueOf(i)); combo.addItem(p); cards.add(p, p.toString()); JComboBox jcb = (JComboBox) e.getSource(); CardLayout cl = (CardLayout) cards.getLayout(); cl.show(cards, jcb.getSelectedItem().toString()); control.add(combo); f.add(cards, BorderLayout.CENTER); f.add(control, BorderLayout.SOUTH); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true);
@Override public void actionPerformed(ActionEvent e) { JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.add(new JLabel("Move to row: "), BorderLayout.WEST); List<Row> rowList = getSolution().getRowList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox rowListField = new JComboBox( rowList.toArray(new Object[rowList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(rowListField); rowListField.setSelectedItem(queen.getRow()); messagePanel.add(rowListField, BorderLayout.CENTER); int result = JOptionPane.showConfirmDialog(NQueensPanel.this.getRootPane(), messagePanel, "Queen in column " + queen.getColumn().getIndex(), JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { Row toRow = (Row) rowListField.getSelectedItem(); solutionBusiness.doChangeMove(queen, "row", toRow); solverAndPersistenceFrame.resetScreen(); } }
gui.add(quality, BorderLayout.WEST); dithering = new JCheckBox("Dithering", false); controls.add(antialiasing); controls.add(fractionalMetrics); textLcdContrast = new JComboBox(VALUES_TEXT_LCD_CONTRAST); JPanel lcdContrastPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); lcdContrastPanel.add(textLcdContrast); controls.add(lcdContrastPanel); textAntialiasing = new JComboBox(VALUES_TEXT_ANTIALIASING); controls.add(textAntialiasing); builder.append( fractionalMetrics.isSelected() ); builder.append("\n"); builder.append( textAntialiasing.getSelectedItem() ); builder.append("\nPNG size: \t"); builder.append(pngSize); textLcdContrast.getSelectedItem()); textAntialiasing.getSelectedItem());
super(); OuterView theGUI = new OuterView(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); add(theGUI); pack(); setVisible(true); JButton button = new JButton("display OuterView's model"); button.addActionListener(new ButtonListener()); add(innerPanel); add(button); super(); String[] items = new String[] { "item 1", "item 2", "item 3" }; JComboBox comboBox = new JComboBox(items); comboBox.addActionListener(new ComboBoxListener()); add(comboBox); @Override public void actionPerformed(ActionEvent ae) { String text = ((JComboBox) ae.getSource()).getSelectedItem() .toString(); firePropertyChange(COMBO_CHANGED, oldValue, text);
@Override public void actionPerformed(ActionEvent e) { JPanel listFieldsPanel = new JPanel(new GridLayout(2, 2)); listFieldsPanel.add(new JLabel("Period:")); Examination examination = getSolution(); List<Period> periodList = examination.getPeriodList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox periodListField = new JComboBox( periodList.toArray(new Object[periodList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(periodListField); periodListField.setSelectedItem(exam.getPeriod()); listFieldsPanel.add(periodListField); listFieldsPanel.add(new JLabel("Room:")); List<Room> roomList = examination.getRoomList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox roomListField = new JComboBox( roomList.toArray(new Object[roomList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(roomListField); roomListField.setSelectedItem(exam.getRoom()); listFieldsPanel.add(roomListField); int result = JOptionPane.showConfirmDialog(ExaminationPanel.this.getRootPane(), listFieldsPanel, "Select period and room", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { Period toPeriod = (Period) periodListField.getSelectedItem(); solutionBusiness.doChangeMove(exam, "period", toPeriod); Room toRoom = (Room) roomListField.getSelectedItem(); solutionBusiness.doChangeMove(exam, "room", toRoom); solverAndPersistenceFrame.resetScreen(); } }
import java.awt.*; import javax.swing.*; class TestCombo { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Integer[] numbers = {1,2,3}; String[] names = {"Ben", "Jill", "Peter"}; JComboBox numberCombo = new JComboBox(numbers); JComboBox nameCombo = new JComboBox(names); JPanel p = new JPanel(new GridLayout(0,1,3,3)); p.add(numberCombo); p.add(nameCombo); JOptionPane.showMessageDialog(null, p); Integer chosenNumber = (Integer)numberCombo.getSelectedItem(); System.out.println("Chosen Number: " + chosenNumber); String chosenName = (String)nameCombo.getSelectedItem(); System.out.println("Chosen Name: " + chosenName); } }); } }
comboBox = new JComboBox( model ); comboBox.addActionListener( this ); comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); getContentPane().add(comboBox, BorderLayout.NORTH ); comboBox = new JComboBox( model ); comboBox.setRenderer( new ItemRenderer() ); comboBox.addActionListener( this ); getContentPane().add(comboBox, BorderLayout.SOUTH ); Item item = (Item)comboBox.getSelectedItem(); System.out.println( item.getId() + " : " + item.getDescription() ); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setVisible( true );
@Override public void actionPerformed(ActionEvent e) { List<SeatDesignation> seatDesignationList = getSolution().getSeatDesignationList(); // Add 1 to array size to add null, which makes the entity unassigned JComboBox seatDesignationListField = new JComboBox( seatDesignationList.toArray(new Object[seatDesignationList.size() + 1])); LabeledComboBoxRenderer.applyToComboBox(seatDesignationListField); seatDesignationListField.setSelectedItem(seatDesignation); int result = JOptionPane.showConfirmDialog(DinnerPartyPanel.this.getRootPane(), seatDesignationListField, "Select seat designation to switch with", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { SeatDesignation switchSeatDesignation = (SeatDesignation) seatDesignationListField.getSelectedItem(); if (seatDesignation != switchSeatDesignation) { solutionBusiness.doSwapMove(seatDesignation, switchSeatDesignation); } solverAndPersistenceFrame.resetScreen(); } }
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); contentPane.add(scrollPane); String colour = (String) cbox.getSelectedItem(); frame.add(contentPane, BorderLayout.CENTER); frame.add(button, BorderLayout.PAGE_END); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); cbox = new JComboBox(colourNames); panel.add(lineNumberLabel);
private SettingsGroup makeOtherGroup() { JComboBox<LangLocale> languageCbx = new JComboBox<>(NLS.getI18nLocales()); for (LangLocale locale : NLS.getI18nLocales()) { if (locale.equals(settings.getLangLocale())) { languageCbx.addActionListener(e -> settings.setLangLocale((LangLocale) languageCbx.getSelectedItem()));
control.setLayout(new GridLayout(0, 1)); for (CabPanel cp : fleet) { control.add(cp); timer.addActionListener(cp.listener); this.add(map, BorderLayout.CENTER); this.add(control, BorderLayout.SOUTH); private int blocks; private JLabel odometer = new JLabel(df.format(0), JLabel.CENTER); private final JComboBox colorBox = new JComboBox(); private final JButton reset = new JButton("Reset"); private final ActionListener listener = new ActionListener() { Hue h = (Hue) colorBox.getSelectedItem(); CabPanel.this.setBackground(h.getColor()); update(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FleetPanel fp = new FleetPanel(); f.add(fp); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); fp.start();