List of usage examples for javax.swing JComboBox setVisible
@BeanProperty(hidden = true, visualUpdate = true) public void setVisible(boolean aFlag)
From source file:Main.java
public static void main(String[] args) { JFrame result = new JFrame(); JComboBox<String> combobox = new JComboBox<>(new String[] { "foo", "bar", "aaa", "Hello World" }); result.add(combobox, BorderLayout.CENTER); JCheckBox toggleVisibility = new JCheckBox("Toggle visibility"); toggleVisibility.setSelected(combobox.isVisible()); toggleVisibility.addItemListener(e -> { combobox.setVisible(e.getStateChange() == ItemEvent.SELECTED); });//from ww w. ja v a 2s. com result.add(toggleVisibility, BorderLayout.SOUTH); result.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result.pack(); result.setVisible(true); }
From source file:JComboBoxDemo.java
public JComboBoxDemo() { JComboBox itemsComboBox = new JComboBox(new String[] { "A", "L", "M" }); itemsComboBox.setEditable(true);/*from w w w. j a v a2 s .co m*/ itemsComboBox.setMaximumRowCount(3); this.getContentPane().add(itemsComboBox); itemsComboBox.setVisible(true); applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT); this.validate(); this.repaint(); }
From source file:Main.java
public Main() { JComboBox itemsComboBox = new JComboBox(new String[] { "A", "L", "M" }); itemsComboBox.setEditable(true);//from www . jav a 2s. c o m itemsComboBox.setMaximumRowCount(3); this.getContentPane().add(itemsComboBox); itemsComboBox.setVisible(true); applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT); this.validate(); this.repaint(); }
From source file:lu.lippmann.cdb.datasetview.tabs.ScatterPlotTabView.java
private void update0(final Instances dataSet, int xidx, int yidx, int coloridx, final boolean asSerie) { System.out.println(xidx + " " + yidx); this.panel.removeAll(); if (xidx == -1) xidx = 0;// w w w . ja v a2s . c o m if (yidx == -1) yidx = 1; if (coloridx == -1) coloridx = 0; final Object[] numericAttrNames = WekaDataStatsUtil.getNumericAttributesNames(dataSet).toArray(); final JComboBox xCombo = new JComboBox(numericAttrNames); xCombo.setBorder(new TitledBorder("x")); xCombo.setSelectedIndex(xidx); final JComboBox yCombo = new JComboBox(numericAttrNames); yCombo.setBorder(new TitledBorder("y")); yCombo.setSelectedIndex(yidx); final JCheckBox jcb = new JCheckBox("Draw lines"); jcb.setSelected(asSerie); final JComboBox colorCombo = new JComboBox(numericAttrNames); colorCombo.setBorder(new TitledBorder("color")); colorCombo.setSelectedIndex(coloridx); colorCombo.setVisible(dataSet.classIndex() < 0); xCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(), colorCombo.getSelectedIndex(), jcb.isSelected()); } }); yCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(), colorCombo.getSelectedIndex(), jcb.isSelected()); } }); colorCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(), colorCombo.getSelectedIndex(), jcb.isSelected()); } }); jcb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(), colorCombo.getSelectedIndex(), jcb.isSelected()); } }); final JXPanel comboPanel = new JXPanel(); comboPanel.setLayout(new GridLayout(1, 0)); comboPanel.add(xCombo); comboPanel.add(yCombo); comboPanel.add(colorCombo); comboPanel.add(jcb); this.panel.add(comboPanel, BorderLayout.NORTH); final java.util.List<Integer> numericAttrIdx = WekaDataStatsUtil.getNumericAttributesIndexes(dataSet); final ChartPanel scatterplotChartPanel = buildChartPanel(dataSet, numericAttrIdx.get(xidx), numericAttrIdx.get(yidx), numericAttrIdx.get(coloridx), asSerie); this.panel.add(scatterplotChartPanel, BorderLayout.CENTER); this.panel.repaint(); this.panel.updateUI(); }
From source file:com.entertailion.java.fling.FlingFrame.java
public FlingFrame(String appId) { super();/*from w w w . j av a 2s . c o m*/ this.appId = appId; rampClient = new RampClient(this); addWindowListener(this); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Locale locale = Locale.getDefault(); resourceBundle = ResourceBundle.getBundle("com/entertailion/java/fling/resources/resources", locale); setTitle(MessageFormat.format(resourceBundle.getString("fling.title"), Fling.VERSION)); JPanel listPane = new JPanel(); // show list of ChromeCast devices detected on the local network listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); JPanel devicePane = new JPanel(); devicePane.setLayout(new BoxLayout(devicePane, BoxLayout.LINE_AXIS)); deviceList = new JComboBox(); deviceList.addActionListener(this); devicePane.add(deviceList); URL url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/refresh.png"); ImageIcon icon = new ImageIcon(url, resourceBundle.getString("button.refresh")); refreshButton = new JButton(icon); refreshButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // refresh the list of devices if (deviceList.getItemCount() > 0) { deviceList.setSelectedIndex(0); } discoverDevices(); } }); refreshButton.setToolTipText(resourceBundle.getString("button.refresh")); devicePane.add(refreshButton); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/settings.png"); icon = new ImageIcon(url, resourceBundle.getString("settings.title")); settingsButton = new JButton(icon); settingsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JTextField transcodingExtensions = new JTextField(50); transcodingExtensions.setText(transcodingExtensionValues); JTextField transcodingParameters = new JTextField(50); transcodingParameters.setText(transcodingParameterValues); JPanel myPanel = new JPanel(new BorderLayout()); JPanel labelPanel = new JPanel(new GridLayout(3, 1)); JPanel fieldPanel = new JPanel(new GridLayout(3, 1)); myPanel.add(labelPanel, BorderLayout.WEST); myPanel.add(fieldPanel, BorderLayout.CENTER); labelPanel.add(new JLabel(resourceBundle.getString("transcoding.extensions"), JLabel.RIGHT)); fieldPanel.add(transcodingExtensions); labelPanel.add(new JLabel(resourceBundle.getString("transcoding.parameters"), JLabel.RIGHT)); fieldPanel.add(transcodingParameters); labelPanel.add(new JLabel(resourceBundle.getString("device.manual"), JLabel.RIGHT)); JPanel devicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); final JComboBox manualDeviceList = new JComboBox(); if (manualServers.size() == 0) { manualDeviceList.setVisible(false); } else { for (DialServer dialServer : manualServers) { manualDeviceList.addItem(dialServer); } } devicePanel.add(manualDeviceList); JButton addButton = new JButton(resourceBundle.getString("device.manual.add")); addButton.setToolTipText(resourceBundle.getString("device.manual.add.tooltip")); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JTextField name = new JTextField(); JTextField ipAddress = new JTextField(); Object[] message = { resourceBundle.getString("device.manual.name") + ":", name, resourceBundle.getString("device.manual.ipaddress") + ":", ipAddress }; int option = JOptionPane.showConfirmDialog(null, message, resourceBundle.getString("device.manual"), JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { try { manualServers.add( new DialServer(name.getText(), InetAddress.getByName(ipAddress.getText()))); Object selected = deviceList.getSelectedItem(); int selectedIndex = deviceList.getSelectedIndex(); deviceList.removeAllItems(); deviceList.addItem(resourceBundle.getString("devices.select")); for (DialServer dialServer : servers) { deviceList.addItem(dialServer); } for (DialServer dialServer : manualServers) { deviceList.addItem(dialServer); } deviceList.invalidate(); if (selectedIndex > 0) { deviceList.setSelectedItem(selected); } else { if (deviceList.getItemCount() == 2) { // Automatically select single device deviceList.setSelectedIndex(1); } } manualDeviceList.removeAllItems(); for (DialServer dialServer : manualServers) { manualDeviceList.addItem(dialServer); } manualDeviceList.setVisible(true); storeProperties(); } catch (UnknownHostException e1) { Log.e(LOG_TAG, "manual IP address", e1); JOptionPane.showMessageDialog(FlingFrame.this, resourceBundle.getString("device.manual.invalidip")); } } } }); devicePanel.add(addButton); JButton removeButton = new JButton(resourceBundle.getString("device.manual.remove")); removeButton.setToolTipText(resourceBundle.getString("device.manual.remove.tooltip")); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object selected = manualDeviceList.getSelectedItem(); manualDeviceList.removeItem(selected); if (manualDeviceList.getItemCount() == 0) { manualDeviceList.setVisible(false); } deviceList.removeItem(selected); deviceList.invalidate(); manualServers.remove(selected); storeProperties(); } }); devicePanel.add(removeButton); fieldPanel.add(devicePanel); int result = JOptionPane.showConfirmDialog(FlingFrame.this, myPanel, resourceBundle.getString("settings.title"), JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { transcodingParameterValues = transcodingParameters.getText(); transcodingExtensionValues = transcodingExtensions.getText(); storeProperties(); } } }); settingsButton.setToolTipText(resourceBundle.getString("settings.title")); devicePane.add(settingsButton); listPane.add(devicePane); // TODO volume = new JSlider(JSlider.VERTICAL, 0, 100, 0); volume.setUI(new MySliderUI(volume)); volume.setMajorTickSpacing(25); // volume.setMinorTickSpacing(5); volume.setPaintTicks(true); volume.setEnabled(true); volume.setValue(100); volume.setToolTipText(resourceBundle.getString("volume.title")); volume.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int position = (int) source.getValue(); rampClient.volume(position / 100.0f); } } }); JPanel centerPanel = new JPanel(new BorderLayout()); // centerPanel.add(volume, BorderLayout.WEST); centerPanel.add(DragHereIcon.makeUI(this), BorderLayout.CENTER); listPane.add(centerPanel); scrubber = new JSlider(JSlider.HORIZONTAL, 0, 100, 0); scrubber.addChangeListener(this); scrubber.setMajorTickSpacing(25); scrubber.setMinorTickSpacing(5); scrubber.setPaintTicks(true); scrubber.setEnabled(false); listPane.add(scrubber); // panel of playback buttons JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); label = new JLabel("00:00:00"); buttonPane.add(label); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/play.png"); icon = new ImageIcon(url, resourceBundle.getString("button.play")); playButton = new JButton(icon); playButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rampClient.play(); } }); buttonPane.add(playButton); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/pause.png"); icon = new ImageIcon(url, resourceBundle.getString("button.pause")); pauseButton = new JButton(icon); pauseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rampClient.pause(); } }); buttonPane.add(pauseButton); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/stop.png"); icon = new ImageIcon(url, resourceBundle.getString("button.stop")); stopButton = new JButton(icon); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rampClient.stop(); setDuration(0); scrubber.setValue(0); scrubber.setEnabled(false); } }); buttonPane.add(stopButton); listPane.add(buttonPane); getContentPane().add(listPane); createProgressDialog(); startWebserver(); discoverDevices(); }
From source file:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java
/** * // ww w . j a v a2 s . c o m */ private void addUserToDS() { final Vector<String> wsList = new Vector<String>(); final Vector<String> instItems = new Vector<String>(); String addStr = getResourceString("ADD"); instItems.add(addStr); wsList.add(addStr); for (String fullName : cloudHelper.getInstList()) { String[] toks = StringUtils.split(fullName, '\t'); instItems.add(toks[0]); wsList.add(toks[1]); } final JTextField userNameTF = createTextField(20); final JTextField passwordTF = createTextField(20); final JLabel pwdLbl = createI18NFormLabel("Password"); final JLabel statusLbl = createLabel(""); final JCheckBox isNewUser = UIHelper.createCheckBox("Is New User"); final JLabel instLbl = createI18NFormLabel("Insitution"); final JComboBox instCmbx = UIHelper.createComboBox(instItems.toArray()); if (instItems.size() == 2) { instCmbx.setSelectedIndex(1); } CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,8px,p")); pb.add(createI18NLabel("Add New or Existing User to DataSet"), cc.xyw(1, 1, 3)); pb.add(createI18NFormLabel("Username"), cc.xy(1, 3)); pb.add(userNameTF, cc.xy(3, 3)); pb.add(pwdLbl, cc.xy(1, 5)); pb.add(passwordTF, cc.xy(3, 5)); pb.add(instLbl, cc.xy(1, 7)); pb.add(instCmbx, cc.xy(3, 7)); pb.add(isNewUser, cc.xy(3, 9)); pb.add(statusLbl, cc.xyw(1, 11, 3)); pb.setDefaultDialogBorder(); pwdLbl.setVisible(false); passwordTF.setVisible(false); instLbl.setVisible(false); instCmbx.setVisible(false); final CustomDialog dlg = new CustomDialog(this, "Add User", true, OKCANCEL, pb.getPanel()) { @Override protected void okButtonPressed() { String usrName = userNameTF.getText(); if (cloudHelper.isUserNameOK(usrName)) { String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex()); if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) { super.okButtonPressed(); } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add usr: %s to the DataSet guid: %s", usrName, collGuid)); } } else if (isNewUser.isSelected()) { String pwdStr = passwordTF.getText(); String guid = null; if (instCmbx.getSelectedIndex() == 0) { // InstDlg instDlg = new InstDlg(cloudHelper); // if (!instDlg.isInstOK()) // { // instDlg.createUI(); // instDlg.pack(); // centerAndShow(instDlg, 600, null); // if (instDlg.isCancelled()) // { // return; // } // //guid = instDlg.getGuid()(); // } } else { //webSite = wsList.get(instCmbx.getSelectedIndex()); } if (guid != null) { String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex()); if (cloudHelper.addNewUser(usrName, pwdStr, guid)) { if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) { ManageDataSetsDlg.this.loadUsersForDataSetsIntoJList(); super.okButtonPressed(); } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add%s to the DataSet %s", usrName, collGuid)); } } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add%s to the DataSet %s", usrName, collGuid)); } } else { // error } } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("'%s' doesn't exist.", usrName)); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { statusLbl.setText(""); String usrNmStr = userNameTF.getText(); boolean hasData = StringUtils.isNotEmpty(usrNmStr) && (!isNewUser.isSelected() || StringUtils.isNotEmpty(passwordTF.getText())) && UIHelper.isValidEmailAddress(usrNmStr); dlg.getOkBtn().setEnabled(hasData); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); final Color textColor = userNameTF.getForeground(); FocusAdapter fa = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { JTextField tf = (JTextField) e.getSource(); if (!tf.getForeground().equals(textColor)) { tf.setText(""); tf.setForeground(textColor); } } @Override public void focusLost(FocusEvent e) { JTextField tf = (JTextField) e.getSource(); if (tf.getText().length() == 0) { tf.setText("Enter email address"); tf.setForeground(Color.LIGHT_GRAY); } } }; userNameTF.addFocusListener(fa); userNameTF.setText("Enter email address"); userNameTF.setForeground(Color.LIGHT_GRAY); isNewUser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean isSel = isNewUser.isSelected(); pwdLbl.setVisible(isSel); passwordTF.setVisible(isSel); instLbl.setVisible(isSel); instCmbx.setVisible(isSel); Dimension s = dlg.getSize(); int hgt = isNewUser.getSize().height + 4 + instCmbx.getSize().height; s.height += isSel ? hgt : -hgt; dlg.setSize(s); } }); dlg.createUI(); dlg.getOkBtn().setEnabled(false); centerAndShow(dlg); if (!dlg.isCancelled()) { loadUsersForDataSetsIntoJList(); } }