List of usage examples for javax.swing JComboBox JComboBox
public JComboBox(Vector<E> items)
JComboBox
that contains the elements in the specified Vector. From source file:MainClass.java
public MainClass() { super("Table With DefaultCellEditor Example"); setSize(500, 300);//from ww w .j a v a 2s . c om setDefaultCloseOperation(EXIT_ON_CLOSE); JTable table = new JTable(new AbstractTableModel() { ColorName data[] = { colors[0], colors[1], colors[2], colors[3], colors[4], colors[0], colors[1], colors[2], colors[3], colors[4] }; public int getColumnCount() { return 3; } public int getRowCount() { return 10; } public Object getValueAt(int r, int c) { switch (c) { case 0: return (r + 1) + "."; case 1: return "Some pithy quote #" + r; case 2: return data[r]; } return "Bad Column"; } public Class getColumnClass(int c) { if (c == 2) return ColorName.class; return String.class; } public boolean isCellEditable(int r, int c) { return c == 2; } public void setValueAt(Object value, int r, int c) { data[r] = (ColorName) value; } }); table.setDefaultEditor(ColorName.class, new DefaultCellEditor(new JComboBox(colors))); table.setDefaultRenderer(ColorName.class, new DefaultTableCellRenderer()); table.setRowHeight(20); getContentPane().add(new JScrollPane(table)); }
From source file:GroupLayoutTest.java
public FontFrame() { setTitle("GroupLayoutTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); ActionListener listener = new FontAction(); // construct components JLabel faceLabel = new JLabel("Face: "); face = new JComboBox(new String[] { "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput" }); face.addActionListener(listener);//ww w . j a va 2 s.com JLabel sizeLabel = new JLabel("Size: "); size = new JComboBox(new String[] { "8", "10", "12", "15", "18", "24", "36", "48" }); size.addActionListener(listener); bold = new JCheckBox("Bold"); bold.addActionListener(listener); italic = new JCheckBox("Italic"); italic.addActionListener(listener); sample = new JTextArea(); sample.setText("The quick brown fox jumps over the lazy dog"); sample.setEditable(false); sample.setLineWrap(true); sample.setBorder(BorderFactory.createEtchedBorder()); pane = new JScrollPane(sample); GroupLayout layout = new GroupLayout(getContentPane()); setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(faceLabel).addComponent(sizeLabel)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent(size).addComponent(face))) .addComponent(italic).addComponent(bold)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(pane) .addContainerGap())); layout.linkSize(SwingConstants.HORIZONTAL, new java.awt.Component[] { face, size }); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(pane, GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(face).addComponent(faceLabel)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(size).addComponent(sizeLabel)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(italic, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(bold, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addContainerGap())); }
From source file:GridBagLayoutTest.java
public FontFrame() { setTitle("GridBagLayoutTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); GridBagLayout layout = new GridBagLayout(); setLayout(layout);//from ww w. ja va2s . c o m ActionListener listener = new FontAction(); // construct components JLabel faceLabel = new JLabel("Face: "); face = new JComboBox(new String[] { "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput" }); face.addActionListener(listener); JLabel sizeLabel = new JLabel("Size: "); size = new JComboBox(new String[] { "8", "10", "12", "15", "18", "24", "36", "48" }); size.addActionListener(listener); bold = new JCheckBox("Bold"); bold.addActionListener(listener); italic = new JCheckBox("Italic"); italic.addActionListener(listener); sample = new JTextArea(); sample.setText("The quick brown fox jumps over the lazy dog"); sample.setEditable(false); sample.setLineWrap(true); sample.setBorder(BorderFactory.createEtchedBorder()); // add components to grid, using GBC convenience class add(faceLabel, new GBC(0, 0).setAnchor(GBC.EAST)); add(face, new GBC(1, 0).setFill(GBC.HORIZONTAL).setWeight(100, 0).setInsets(1)); add(sizeLabel, new GBC(0, 1).setAnchor(GBC.EAST)); add(size, new GBC(1, 1).setFill(GBC.HORIZONTAL).setWeight(100, 0).setInsets(1)); add(bold, new GBC(0, 2, 2, 1).setAnchor(GBC.CENTER).setWeight(100, 100)); add(italic, new GBC(0, 3, 2, 1).setAnchor(GBC.CENTER).setWeight(100, 100)); add(sample, new GBC(2, 0, 1, 4).setFill(GBC.BOTH).setWeight(100, 100)); }
From source file:layout.GridLayoutDemo.java
public void initGaps() { horGapComboBox = new JComboBox(gapList); verGapComboBox = new JComboBox(gapList); }
From source file:layout.CardLayoutDemo.java
public void addComponentToPane(Container pane) { //Put the JComboBox in a JPanel to get a nicer look. JPanel comboBoxPane = new JPanel(); //use FlowLayout String comboBoxItems[] = { BUTTONPANEL, TEXTPANEL }; JComboBox cb = new JComboBox(comboBoxItems); cb.setEditable(false);//from w w w . j av a 2 s. c om cb.addItemListener(this); comboBoxPane.add(cb); //Create the "cards". JPanel card1 = new JPanel(); card1.add(new JButton("Button 1")); card1.add(new JButton("Button 2")); card1.add(new JButton("Button 3")); JPanel card2 = new JPanel(); card2.add(new JTextField("TextField", 20)); //Create the panel that contains the "cards". cards = new JPanel(new CardLayout()); cards.add(card1, BUTTONPANEL); cards.add(card2, TEXTPANEL); pane.add(comboBoxPane, BorderLayout.PAGE_START); pane.add(cards, BorderLayout.CENTER); }
From source file:ArcApp.java
public ArcApp() { super(new BorderLayout()); canvas = new MyCanvas(); int width = 600; int height = 55; sliderX = setSlider(0, width, width / 4, width / 2, width / 4); sliderY = setSlider(0, height, height / 4, height / 2, height / 4); sliderWidth = setSlider(0, width, width / 2, width / 2, width / 4); sliderHeight = setSlider(0, height, height / 2, height / 2, height / 4); sliderT0 = setSlider(0, 360, 45, 180, 45); sliderT = setSlider(0, 360, 135, 180, 45); JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayout(3, 3)); panel1.add(new JLabel("Location (x,y): ", JLabel.RIGHT)); panel1.add(sliderX);/* ww w .j a v a2 s . c o m*/ panel1.add(sliderY); panel1.add(new JLabel("Size (w,h): ", JLabel.RIGHT)); panel1.add(sliderWidth); panel1.add(sliderHeight); panel1.add(new JLabel("Angles (Th0, Th): ", JLabel.RIGHT)); panel1.add(sliderT0); panel1.add(sliderT); add(panel1, BorderLayout.NORTH); arcBox = new JComboBox(arcLabels); arcBox.setSelectedIndex(0); arcBox.setAlignmentX(Component.LEFT_ALIGNMENT); arcBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.arcType = arcTypes[cb.getSelectedIndex()]; canvas.repaint(); } }); fillBox = new JComboBox(colorLabels); fillBox.setSelectedIndex(0); fillBox.setAlignmentX(Component.LEFT_ALIGNMENT); fillBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.fillColor = colors[cb.getSelectedIndex()]; canvas.repaint(); } }); JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayout(1, 4)); panel2.add(new JLabel("Arc Type: ", JLabel.RIGHT)); panel2.add(arcBox); panel2.add(new JLabel("Fill Type: ", JLabel.RIGHT)); panel2.add(fillBox); add(panel2, BorderLayout.SOUTH); add(canvas, BorderLayout.CENTER); }
From source file:Main.java
/** * Creates a channel selector combobox.//w w w. j a v a 2 s.com * * @param aChannelCount * the number of channels to include in the combobox options; * @param aDefaultSelectedindex * the default selected index; * @param aAddUnusedOption * <code>true</code> to add "unused" as first option, * <code>false</code> to omit this option. * @return a combobox with channel selector options. */ private static JComboBox internalCreateChannelSelector(final int aChannelCount, final int aDefaultSelectedindex, final boolean aAddUnusedOption) { int modelSize = Math.max(0, Math.min(32, aChannelCount)); if (aAddUnusedOption) { modelSize++; } final String dataChannels[] = new String[modelSize]; int i = 0; if (aAddUnusedOption) { dataChannels[i++] = "Unused"; } for (; i < modelSize; i++) { final int index = aAddUnusedOption ? i - 1 : i; dataChannels[i] = String.format("Channel %d", Integer.valueOf(index)); } int selectedIndex = aDefaultSelectedindex < 0 ? 0 : aDefaultSelectedindex % modelSize; final JComboBox result = new JComboBox(dataChannels); result.setSelectedIndex(selectedIndex); return result; }
From source file:FormularioGuardarEstudio.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - verdura henrion label1 = new JLabel(); pacientesCombo = new JComboBox(obtenerPacientes().toArray()); label2 = new JLabel(); label3 = new JLabel(); label4 = new JLabel(); label5 = new JLabel(); nombreEstudio = new JTextField(); scrollPane1 = new JScrollPane(); descripcion = new JTextArea(); descripcion.setLineWrap(true);//from ww w . j a v a2s.c o m descripcion.setWrapStyleWord(true); notas = new JTextArea(); notas.setLineWrap(true); notas.setWrapStyleWord(true); button1 = new JButton(); mensajeRespuesta = new JLabel(); //======== this ======== setTitle("Guardar Estudio"); Container contentPane = getContentPane(); //---- label1 ---- label1.setText("Paciente:"); label1.setFont(new Font("Calibri", Font.BOLD, 14)); //---- label2 ---- label2.setText("Datos del Estudio"); label2.setFont(new Font("Calibri", Font.BOLD, 14)); //---- label3 ---- label3.setText("Nombre Del Estudio:"); //---- label4 ---- label4.setText("Descripci\u00f3n:"); //---- label5 ---- label5.setText("Notas:"); //======== scrollPane1 ======== { scrollPane1.setViewportView(descripcion); } //---- button1 ---- button1.setText("Guardar Estudio"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clickGuardarEstudio(e); } }); //---- mensajeRespuesta ---- mensajeRespuesta.setText("_"); mensajeRespuesta.setHorizontalAlignment(SwingConstants.CENTER); GroupLayout contentPaneLayout = new GroupLayout(contentPane); contentPane.setLayout(contentPaneLayout); contentPaneLayout.setHorizontalGroup(contentPaneLayout.createParallelGroup().addGroup(contentPaneLayout .createSequentialGroup() .addGroup(contentPaneLayout.createParallelGroup().addGroup(contentPaneLayout.createSequentialGroup() .addContainerGap().addGroup(contentPaneLayout.createParallelGroup().addComponent(label4) .addComponent(label1, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE) .addComponent( pacientesCombo, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE) .addComponent(label2) .addGroup(contentPaneLayout.createSequentialGroup().addComponent(label3) .addGap(18, 18, 18).addComponent(nombreEstudio, GroupLayout.PREFERRED_SIZE, 140, GroupLayout.PREFERRED_SIZE)) .addGroup(contentPaneLayout.createSequentialGroup().addComponent(label5) .addGroup(contentPaneLayout.createParallelGroup().addGroup(contentPaneLayout .createSequentialGroup().addGap(83, 83, 83) .addGroup(contentPaneLayout .createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE) .addComponent(notas, GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE))) .addGroup(contentPaneLayout.createSequentialGroup() .addGap(48, 48, 48).addComponent(mensajeRespuesta, GroupLayout.PREFERRED_SIZE, 215, GroupLayout.PREFERRED_SIZE)))))) .addGroup(contentPaneLayout.createSequentialGroup().addGap(142, 142, 142) .addComponent(button1))) .addContainerGap(18, Short.MAX_VALUE))); contentPaneLayout.setVerticalGroup(contentPaneLayout.createParallelGroup() .addGroup(contentPaneLayout.createSequentialGroup().addContainerGap() .addComponent(label1, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(pacientesCombo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(label2).addGap(18, 18, 18) .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label3).addComponent(nombreEstudio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(contentPaneLayout.createParallelGroup().addComponent(label4).addComponent( scrollPane1, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)) .addGap(11, 11, 11) .addGroup(contentPaneLayout.createParallelGroup().addComponent(label5).addComponent(notas, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(mensajeRespuesta, GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(button1) .addContainerGap())); pack(); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents }
From source file:com.emental.mindraider.ui.dialogs.FtsJDialog.java
public FtsJDialog() { super(Messages.getString("FtsJDialog.title")); JPanel dialogPanel = new JPanel(); dialogPanel.setBorder(new EmptyBorder(5, 10, 0, 10)); dialogPanel.setLayout(new BorderLayout()); JPanel contentAndButtons = new JPanel(new GridLayout(2, 1)); JPanel contentPanel = new JPanel(new BorderLayout()); // 1a.//from w ww . ja va 2s . c o m // TODO add help like in eclipse contentPanel.add(new JLabel(Messages.getString("FtsJDialog.searchString")), BorderLayout.NORTH); // 1b. String[] knownSearches = new String[] { "", "RDF", "mind", "concept", "China" }; ftsCombo = new JComboBox(knownSearches); ftsCombo.setPreferredSize(new Dimension(200, 18)); ftsCombo.setEditable(true); ftsCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if ("comboBoxEdited".equals(e.getActionCommand())) { search(); } } }); contentPanel.add(ftsCombo, BorderLayout.SOUTH); contentAndButtons.add(contentPanel); // 2. JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5)); JButton searchButton = new JButton(Messages.getString("FtsJDialog.searchButton")); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { search(); } }); p.add(searchButton); JButton cancelButton = new JButton(Messages.getString("FtsJDialog.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); p.add(cancelButton); contentAndButtons.add(p); dialogPanel.add(contentAndButtons, BorderLayout.CENTER); getContentPane().add(dialogPanel, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); }
From source file:ja.lingo.application.gui.main.settings.appearance.AppearanceGui.java
public AppearanceGui(Model model) { model.addApplicationModelListener(new ModelAdapter() { public void settingsUpdated(Preferences preferences) { setSelectedFontSize(preferences.getFontSize()); setSelectedFontFace(preferences.getFontFace()); dropZoneCheckBox.setSelected(preferences.isDropZoneVisible()); memoryBarCheckBox.setSelected(preferences.isMemoryBarVisible()); }/*from w w w .j a v a2 s . c o m*/ }); dropZoneCheckBox = new JCheckBox(resources.text("showDropZone")); fontSizeComboBox = new JComboBox(new Integer[] { 12, 13, DEFAULT_FONT_SIZE, 15, 16, 17 }); memoryBarCheckBox = new JCheckBox(resources.text("showMemoryBar")); JPanel fontSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Gaps.GAP5, 0)); fontSizePanel.add(resources.label("fontSize")); fontSizePanel.add(fontSizeComboBox); fontSizePanel.add(resources.label("requiresRestart")); gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED }, { TableLayout.PREFERRED, // 0: font face Gaps.GAP5, TableLayout.PREFERRED, // 2: font size Gaps.GAP5, TableLayout.PREFERRED, // 4: drop-zone Gaps.GAP5, TableLayout.PREFERRED, // 6: memory bar } })); JPanel fontFacePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Gaps.GAP5, 0)); fontFacePanel.add(resources.label("fontFace")); GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFaceComboBox = new JComboBox(gEnv.getAvailableFontFamilyNames()); fontFaceComboBox.setMaximumRowCount(10); fontFacePanel.add(fontFaceComboBox); fontFacePanel.add(resources.label("requiresRestart")); gui.add(fontFacePanel, "0, 0"); gui.add(fontSizePanel, "0, 2"); gui.add(dropZoneCheckBox, "0, 4"); gui.add(memoryBarCheckBox, "0, 6"); Gaps.applyBorder5(gui); ActionBinder.bind(this); }