Java Code Examples for javax.swing.JToggleButton#addItemListener()
The following examples show how to use
javax.swing.JToggleButton#addItemListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolBarManager.java From openAGV with Apache License 2.0 | 6 votes |
/** * Method addSelectionToolButton must have been invoked prior to this on the * JToolBar. * * @param toolBar * @param editor * @param tool * @param toolTipText * @param labels * @return */ private JToggleButton addToolButton(JToolBar toolBar, DrawingEditor editor, Tool tool, String toolTipText, ImageIcon iconBase) { JToggleButton toggleButton = new JToggleButton(); toggleButton.setIcon(iconBase); toggleButton.setText(null); toggleButton.setToolTipText(toolTipText); toggleButton.addItemListener(new ToolButtonListener(tool, editor)); // toggleButton.setFocusable(false); ToolListener toolHandler = (ToolListener) toolBar.getClientProperty("toolHandler"); tool.addToolListener(toolHandler); ButtonGroup group = (ButtonGroup) toolBar.getClientProperty("toolButtonGroup"); group.add(toggleButton); toolBar.add(toggleButton); return toggleButton; }
Example 2
Source File: DrawingViewPlacardPanel.java From openAGV with Apache License 2.0 | 6 votes |
/** * Creates a button to toggle the grid in the drawing. * * @param view The DrawingView the button will belong to. * @return The created button. */ private JToggleButton toggleConstrainerButton(final OpenTCSDrawingView drawingView) { final JToggleButton toggleButton = new JToggleButton(); toggleButton.setToolTipText( labels.getString("drawingViewPlacardPanel.button_toggleGrid.tooltipText") ); toggleButton.setIcon(ImageDirectory.getImageIcon("/menu/view-split.png")); toggleButton.setMargin(new Insets(0, 0, 0, 0)); toggleButton.setFocusable(false); toggleButton.addItemListener( (ItemEvent event) -> drawingView.setConstrainerVisible(toggleButton.isSelected()) ); return toggleButton; }
Example 3
Source File: DrawingViewPlacardPanel.java From openAGV with Apache License 2.0 | 6 votes |
/** * Creates a button to toglle the labels. * * @param view The DrawingView the button will belong to. * @return The created button. */ private JToggleButton toggleLabelsButton(final OpenTCSDrawingView drawingView) { final JToggleButton toggleButton = new JToggleButton(); toggleButton.setToolTipText( labels.getString("drawingViewPlacardPanel.button_toggleLabels.tooltipText") ); toggleButton.setIcon(ImageDirectory.getImageIcon("/menu/comment-add.16.png")); toggleButton.setMargin(new Insets(0, 0, 0, 0)); toggleButton.setFocusable(false); toggleButton.addItemListener( (ItemEvent event) -> drawingView.setLabelsVisible(toggleButton.isSelected()) ); return toggleButton; }
Example 4
Source File: DrawingViewPlacardPanel.java From openAGV with Apache License 2.0 | 6 votes |
/** * Creates a button to toggle the blocks in the drawing. * * @param view The DrawingView the button will belong to. * @return The created button. */ private JToggleButton toggleBlocksButton(final OpenTCSDrawingView drawingView) { final JToggleButton toggleButton = new JToggleButton(); toggleButton.setToolTipText( labels.getString("drawingViewPlacardPanel.button_toggleBlocks.tooltipText") ); toggleButton.setIcon(ImageDirectory.getImageIcon("/tree/block.18x18.png")); toggleButton.setMargin(new Insets(0, 0, 0, 0)); toggleButton.setFocusable(false); toggleButton.addItemListener( (ItemEvent event) -> drawingView.setBlocksVisible(toggleButton.isSelected()) ); return toggleButton; }
Example 5
Source File: StatisticsPanel.java From netbeans with Apache License 2.0 | 6 votes |
private JToggleButton newOptionButton(Icon icon, String tooltip, String accessibleName, final String property) { JToggleButton newButton = new JToggleButton(icon); newButton.setToolTipText(tooltip); newButton.getAccessibleContext().setAccessibleName(accessibleName); boolean isSelected = NbPreferences.forModule(StatisticsPanel.class).getBoolean(property, false); newButton.setSelected(isSelected); newButton.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { boolean selected; switch (e.getStateChange()) { case ItemEvent.SELECTED: selected = true; break; case ItemEvent.DESELECTED: selected = false; break; default: return; } ResultWindow.getInstance().updateOptionStatus(property, selected); } }); return newButton; }
Example 6
Source File: WebORTable.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private void init() { setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS)); setFloatable(false); add(new javax.swing.Box.Filler(new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 32767))); JLabel label = new JLabel("Properties"); label.setFont(new Font("Default", Font.BOLD, 12)); add(label); add(new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767))); add(Utils.createButton("Add Row", "add", "Ctrl+Plus", WebORTable.this)); add(Utils.createButton("Delete Rows", "remove", "Ctrl+Minus", WebORTable.this)); addSeparator(); add(Utils.createButton("Move Rows Up", "up", "Ctrl+Up", WebORTable.this)); add(Utils.createButton("Move Rows Down", "down", "Ctrl+Down", WebORTable.this)); addSeparator(); frameToggle = new JToggleButton(Utils.getIconByResourceName("/ui/resources/or/web/propViewer")); frameToggle.addItemListener(WebORTable.this); frameToggle.setToolTipText("Show/Hide Frame Property"); frameToggle.setActionCommand("Toggle Frame"); add(frameToggle); }
Example 7
Source File: SwitchController.java From Ardulink-1 with Apache License 2.0 | 5 votes |
/** * Create the panel. */ public SwitchController() { setPreferredSize(new Dimension(125, 75)); setLayout(null); pinComboBoxModel = new IntMinMaxModel(0, 40).withSelectedItem(3); JComboBox pinComboBox = new JComboBox(pinComboBoxModel); pinComboBox.setBounds(66, 11, 47, 22); add(pinComboBox); JLabel label = new JLabel("Power Pin:"); label.setFont(new Font("SansSerif", Font.PLAIN, 11)); label.setBounds(10, 15, 59, 14); add(label); switchToggleButton = new JToggleButton("Off"); switchToggleButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int pin = pinComboBoxModel.getSelectedItem().intValue(); if(e.getStateChange() == ItemEvent.SELECTED) { switchToggleButton.setText("On"); link.sendPowerPinSwitch(pin, IProtocol.POWER_HIGH); } else if(e.getStateChange() == ItemEvent.DESELECTED) { switchToggleButton.setText("Off"); link.sendPowerPinSwitch(pin, IProtocol.POWER_LOW); } } }); switchToggleButton.setBounds(10, 38, 103, 23); add(switchToggleButton); }
Example 8
Source File: ToolBarManager.java From openAGV with Apache License 2.0 | 5 votes |
/** * * @param toolBar * @param editor */ private JToggleButton addDragToolButton(JToolBar toolBar, DrawingEditor editor) { final JToggleButton button = new JToggleButton(); dragTool = new DragTool(); editor.setTool(dragTool); if (!(toolBar.getClientProperty("toolHandler") instanceof ToolListener)) { ToolListener toolHandler = new ToolAdapter() { @Override public void toolDone(ToolEvent event) { button.setSelected(true); } }; toolBar.putClientProperty("toolHandler", toolHandler); } URL url = getClass().getResource(ImageDirectory.DIR + "/toolbar/cursor-opened-hand.png"); button.setIcon(new ImageIcon(url)); button.setText(null); button.setToolTipText(ResourceBundleUtil.getBundle(I18nPlantOverview.TOOLBAR_PATH) .getString("toolBarManager.button_dragTool.tooltipText")); button.setSelected(false); button.addItemListener(new ToolButtonListener(dragTool, editor)); // button.setFocusable(false); ButtonGroup group = (ButtonGroup) toolBar.getClientProperty("toolButtonGroup"); group.add(button); toolBar.add(button); return button; }
Example 9
Source File: SwitchController.java From Ardulink-2 with Apache License 2.0 | 5 votes |
/** * Create the panel. */ public SwitchController() { setPreferredSize(new Dimension(125, 75)); setLayout(null); pinComboBoxModel = new IntMinMaxModel(0, 40).withSelectedItem(3); JComboBox pinComboBox = new JComboBox(pinComboBoxModel); pinComboBox.setBounds(66, 11, 47, 22); add(pinComboBox); JLabel label = new JLabel("Power Pin:"); label.setFont(new Font("SansSerif", Font.PLAIN, 11)); label.setBounds(10, 15, 59, 14); add(label); switchToggleButton = new JToggleButton("Off"); switchToggleButton.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { int pin = pinComboBoxModel.getSelectedItem().intValue(); if(e.getStateChange() == ItemEvent.SELECTED) { switchToggleButton.setText("On"); link.sendPowerPinSwitch(pin, true); } else if(e.getStateChange() == ItemEvent.DESELECTED) { switchToggleButton.setText("Off"); link.sendPowerPinSwitch(pin, false); } } }); switchToggleButton.setBounds(10, 38, 103, 23); add(switchToggleButton); }
Example 10
Source File: ImageORTable.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private void init() { add(new javax.swing.Box.Filler(new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 32767))); JLabel label = new JLabel("Properties"); label.setFont(new Font("Default", Font.BOLD, 12)); add(label); add(new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767))); toggleImage = new JToggleButton(Utils.getIconByResourceName("/ui/resources/or/image/image")); toggleImage.addItemListener(ImageORTable.this); toggleImage.setActionCommand("ToggleImage"); toggleImage.setToolTipText("Show/Hide Image"); add(toggleImage); JButton offset = new JButton(Utils.getIconByResourceName("/ui/resources/or/image/findOffset")); offset.addActionListener(ImageORTable.this); offset.setToolTipText("Show Offset"); offset.setActionCommand("Show Offset"); add(offset); JButton findOn = new JButton(Utils.getIconByResourceName("/ui/resources/or/image/findOnScreen")); findOn.addActionListener(ImageORTable.this); findOn.setToolTipText("Find on Screen"); findOn.setActionCommand("Find on Screen"); add(findOn); JButton editor = new JButton(Utils.getIconByResourceName("/ui/resources/or/image/propViewer")); editor.addActionListener(ImageORTable.this); editor.setToolTipText("Show Property Editor"); editor.setActionCommand("Show Property Editor"); add(editor); }
Example 11
Source File: ObjectRepo.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private JToggleButton create(String text) { JToggleButton togg = new JToggleButton(); togg.setIcon(Utils.getIconByResourceName("/ui/resources/or/" + text.toLowerCase())); togg.setToolTipText(text); togg.setActionCommand(text); togg.addItemListener(ObjectRepo.this); bgroup.add(togg); return togg; }
Example 12
Source File: JChoice.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * (Re)constructs the UI. This can be called many times, whenever a * significant value (such as {@link #maximumFastChoices}, or the model) * has changed. */ private void buildGui(){ removeAll(); if(model != null && model.getSize() > 0){ if(model.getSize() > maximumFastChoices){ //use combobox add(combo); }else{ //use buttons //first clear the old buttons, if any exist if(buttonToValueMap.size() > 0){ for(AbstractButton aBtn : buttonToValueMap.keySet()){ aBtn.removeItemListener(sharedItemListener); } } //now create the new buttons buttonToValueMap.clear(); for(int i = 0; i < model.getSize(); i++){ Object aValue = model.getElementAt(i); JToggleButton aButton = new JToggleButton(aValue.toString()); if(defaultButtonMargin != null) aButton.setMargin(defaultButtonMargin); aButton.addItemListener(sharedItemListener); buttonToValueMap.put(aButton, aValue); add(aButton); } } } revalidate(); }
Example 13
Source File: TaskListTopComponent.java From netbeans with Apache License 2.0 | 5 votes |
private void rebuildToolbar() { toolbar.removeAll(); toolbar.setFocusable( false ); //scope buttons List<TaskScanningScope> scopes = ScanningScopeList.getDefault().getTaskScanningScopes(); for( TaskScanningScope scope : scopes ) { final ScopeButton scopeButton = new ScopeButton( taskManager, scope ); scopeButton.setSelected(scope.equals(Settings.getDefault().getActiveScanningScope())); toolbar.add(scopeButton); } toolbar.add( new JToolBar.Separator() ); //filter JToggleButton toggleFilter = new FiltersMenuButton( filters.getActive() ); toolbar.add( toggleFilter ); //grouping & other butons toolbar.addSeparator(); final JToggleButton toggleGroups = new JToggleButton( ImageUtilities.loadImageIcon("org/netbeans/modules/tasklist/ui/resources/groups.png", false)); //NOI18N toggleGroups.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { switchTableModel( e.getStateChange() == ItemEvent.SELECTED ); Settings.getDefault().setGroupTasksByCategory( toggleGroups.isSelected() ); toggleGroups.setToolTipText( toggleGroups.isSelected() ? NbBundle.getMessage( TaskListTopComponent.class, "HINT_TasksAsList" ) //NOI18N : NbBundle.getMessage( TaskListTopComponent.class, "HINT_GrouppedTasks" ) ); //NOI18N } }); toggleGroups.setSelected( Settings.getDefault().getGroupTasksByCategory() ); toggleGroups.setToolTipText( toggleGroups.isSelected() ? NbBundle.getMessage( TaskListTopComponent.class, "HINT_TasksAsList" ) //NOI18N : NbBundle.getMessage( TaskListTopComponent.class, "HINT_GrouppedTasks" ) ); //NOI18N toggleGroups.setFocusable( false ); toolbar.add( toggleGroups ); }
Example 14
Source File: StatisticsPanel.java From netbeans with Apache License 2.0 | 5 votes |
private JToggleButton newShowButton(String iconId, String tooltip, String accessibleName, Status status) { JToggleButton btn = new JToggleButton(ImageUtilities.loadImageIcon(iconId, true)); btn.setToolTipText(tooltip); btn.getAccessibleContext().setAccessibleName(accessibleName); btn.setSelected((filterMask & status.getBitMask()) == 0); btn.addItemListener(new FilterItemListener(status)); return btn; }
Example 15
Source File: CSSStylesSelectionPanel.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates a panel that allows forcing of pseudo-classes. * * @param pseudoClassToggle toggle-button used to show the panel. * @return panel that allows forcing of pseudo-classes. */ private JPanel createPseudoClassPanel(JToggleButton pseudoClassToggle) { final JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2,2)); ResourceBundle bundle = NbBundle.getBundle(CSSStylesSelectionPanel.class); panel.add(createPseudoCheckBox( CSS.PseudoClass.ACTIVE, bundle.getString("CSSStylesSelectionPanel.pseudoClass.active"))); // NOI18N panel.add(createPseudoCheckBox( CSS.PseudoClass.HOVER, bundle.getString("CSSStylesSelectionPanel.pseudoClass.hover"))); // NOI18N panel.add(createPseudoCheckBox( CSS.PseudoClass.FOCUS, bundle.getString("CSSStylesSelectionPanel.pseudoClass.focus"))); // NOI18N panel.add(createPseudoCheckBox( CSS.PseudoClass.VISITED, bundle.getString("CSSStylesSelectionPanel.pseudoClass.visited"))); // NOI18N panel.setVisible(false); pseudoClassToggle.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { JToggleButton source = (JToggleButton)e.getSource(); panel.setVisible(source.isSelected()); } }); return panel; }
Example 16
Source File: JToggleButtonDemo.java From dctb-utfpr-2018-1 with Apache License 2.0 | 5 votes |
JToggleButtonDemo() { //CRIA UM CONTEINER JFRAME JFrame jfrm = new JFrame(" EXEMPLO DE JToggleButton - botão de alternância"); //ESPECIFICA FLOWLAYOUT COMO GERENCIADOR DE LEIAUTE jfrm.setLayout(new FlowLayout()); //FORNECE UM TAMANHO INICIAL PAR AO QUADRO jfrm.setSize(250, 100); //ENCERRA O PROGRAMA QUANDO O USUÁRIO FECHA O APLICATIVO jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //CRIA UM RÓTULO jlab = new JLabel(" O BOTÃO NÃO ESTÁ SELECIONADO "); //CRIA UM BOTÃO DE ALTERNÂNCIA jtbn = new JToggleButton("On/Off"); // ADICIONA UM OUVINTE DE ITENS PARA O BOTÃO DE ALTERNÂNCIA //USA UM ITEM LISTENER PARA TRATAR EVENTOS DO BOTÃO DE ALTERNÂNCIA //USA IS SELECTED() PARA DETERMINAR O ESTADO DO BOTÃO jtbn.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { if (jtbn.isSelected()) { jlab.setText(" O BOTÃO ESTÁ SELECIONADO" ); } else { jlab.setText(" O BOTÃO NÃO ESTÁ SELECIONADO."); } } }); // ADICIONA O BOTÃO DE ALTERNÂNCIA E O RÓTULO AO PAINEL DE CONTEÚDO jfrm.add(jtbn); jfrm.add(jlab); // Display the frame. jfrm.setVisible(true); }
Example 17
Source File: ToggleSignalButton.java From Ardulink-2 with Apache License 2.0 | 4 votes |
/** * Create the valuePanelOff. */ public ToggleSignalButton() { setLayout(new BorderLayout(0, 0)); configPanel = new JPanel(); add(configPanel, BorderLayout.NORTH); configPanel.setLayout(new BoxLayout(configPanel, BoxLayout.Y_AXIS)); valuePanelOn = new JPanel(); configPanel.add(valuePanelOn); valuePanelOn.setLayout(new BoxLayout(valuePanelOn, BoxLayout.X_AXIS)); valueLabelOn = new JLabel("Value on:"); valueLabelOn.setHorizontalAlignment(SwingConstants.RIGHT); valuePanelOn.add(valueLabelOn); textFieldOn = new JTextField(); valuePanelOn.add(textFieldOn); textFieldOn.setColumns(10); valuePanelOff = new JPanel(); configPanel.add(valuePanelOff); valuePanelOff.setLayout(new BoxLayout(valuePanelOff, BoxLayout.X_AXIS)); valueLabelOff = new JLabel("Value off:"); valueLabelOff.setHorizontalAlignment(SwingConstants.RIGHT); valuePanelOff.add(valueLabelOff); textFieldOff = new JTextField(); textFieldOff.setColumns(10); valuePanelOff.add(textFieldOff); signalButton = new JToggleButton("Off"); signalButton.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { link.sendCustomMessage(getId(), e.getStateChange() == SELECTED ? getValueOn() : getValueOff()); updateSignalButtonText(); } }); add(signalButton); }
Example 18
Source File: DigitalPinStatus.java From Ardulink-2 with Apache License 2.0 | 4 votes |
/** * Create the panel. */ public DigitalPinStatus() { setLayout(new GridLayout(3, 1, 0, 0)); lblStatelabel = new JLabel(LOW); lblStatelabel.setHorizontalAlignment(SwingConstants.CENTER); lblStatelabel.setIcon(LOW_ICON); lblStatelabel.setEnabled(false); add(lblStatelabel); comboPanel = new JPanel(); add(comboPanel); lblPin = new JLabel("Pin:"); comboPanel.add(lblPin); pinComboBoxModel = new IntMinMaxModel(2, 40); pinComboBox = new JComboBox(pinComboBoxModel); comboPanel.add(pinComboBox); tglbtnSensor = new JToggleButton("Sensor off"); tglbtnSensor.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { link.addDigitalReadChangeListener((listener = listener())); tglbtnSensor.setText("Sensor on"); pinComboBox.setEnabled(false); lblStatelabel.setEnabled(true); } else if (e.getStateChange() == ItemEvent.DESELECTED) { link.removeDigitalReadChangeListener(listener); tglbtnSensor.setText("Sensor off"); pinComboBox.setEnabled(true); lblStatelabel.setEnabled(false); } } }); add(tglbtnSensor); }
Example 19
Source File: DigitalPinStatus.java From Ardulink-1 with Apache License 2.0 | 4 votes |
/** * Create the panel. */ public DigitalPinStatus() { setLayout(new GridLayout(3, 1, 0, 0)); lblStatelabel = new JLabel(LOW); lblStatelabel.setHorizontalAlignment(SwingConstants.CENTER); lblStatelabel.setIcon(LOW_ICON); lblStatelabel.setEnabled(false); add(lblStatelabel); comboPanel = new JPanel(); add(comboPanel); lblPin = new JLabel("Pin:"); comboPanel.add(lblPin); pinComboBoxModel = new IntMinMaxModel(2, 40); pinComboBox = new JComboBox(pinComboBoxModel); comboPanel.add(pinComboBox); tglbtnSensor = new JToggleButton("Sensor off"); tglbtnSensor.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if(e.getStateChange() == ItemEvent.SELECTED) { link.addDigitalReadChangeListener((DigitalReadChangeListener)tglbtnSensor.getParent()); tglbtnSensor.setText("Sensor on"); pinComboBox.setEnabled(false); lblStatelabel.setEnabled(true); } else if(e.getStateChange() == ItemEvent.DESELECTED) { link.removeDigitalReadChangeListener((DigitalReadChangeListener)tglbtnSensor.getParent()); tglbtnSensor.setText("Sensor off"); pinComboBox.setEnabled(true); lblStatelabel.setEnabled(false); } } }); add(tglbtnSensor); }