Java Code Examples for javax.swing.JToggleButton#setSelected()
The following examples show how to use
javax.swing.JToggleButton#setSelected() .
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: HorizontalList.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void refresh() { if(blockRefeshWhileLoading) { return; } for(java.awt.Component cmp : getComponents()) { remove(cmp); group.remove((JToggleButton)cmp); } String[] entries = getEntries(); Arrays.sort(entries, String.CASE_INSENSITIVE_ORDER); initLayout(entries.length); for(String current : entries) { JToggleButton button = createButton(current); add(button); String selection = view.getSelectedResource(); if(selection != null && selection.equals(current)) { button.setSelected(true); } button.addActionListener(listener); group.add(button); } revalidate(); repaint(); }
Example 2
Source File: ScenarioEditor.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addTool(final Tool t, JMenu menu, JToolBar toolbar, ButtonGroup menuGroup, ButtonGroup toolbarGroup) { final JToggleButton toggle = new JToggleButton(); final JCheckBoxMenuItem check = new JCheckBoxMenuItem(); Action action = new AbstractAction(t.getName()) { @Override public void actionPerformed(ActionEvent e) { if (currentTool != null) { currentTool.deactivate(); } currentTool = t; toggle.setSelected(true); check.setSelected(true); currentTool.activate(); } }; toggle.setAction(action); check.setAction(action); menu.add(check); toolbar.add(toggle); menuGroup.add(check); toolbarGroup.add(toggle); }
Example 3
Source File: OpenPanel.java From settlers-remake with MIT License | 6 votes |
/** * Initialize the filter buttons */ private void initFilter() { JLabel filterLabel = new JLabel(Labels.getString("mapfilter.title")); filterLabel.putClientProperty(ELFStyle.KEY, ELFStyle.LABEL_SHORT); filterPanel.add(filterLabel); boolean first = true; ButtonGroup group = new ButtonGroup(); for (final EMapFilter filter : EMapFilter.values()) { JToggleButton bt = new JToggleButton(filter.getName()); bt.putClientProperty(ELFStyle.KEY, ELFStyle.TOGGLE_BUTTON_STONE); bt.addActionListener(e -> { currentFilter = filter; searchChanged(); }); if (first) { first = false; bt.setSelected(true); } group.add(bt); filterPanel.add(bt); } }
Example 4
Source File: SeaGlassDesktopIconUI.java From seaglass with Apache License 2.0 | 6 votes |
public void actionPerformed(ActionEvent evt) { if (evt.getSource() instanceof JToggleButton) { // Either iconify the frame or deiconify and activate it. JToggleButton button = (JToggleButton) evt.getSource(); try { boolean selected = button.isSelected(); if (!selected && !frame.isIconifiable()) { button.setSelected(true); } else { frame.setIcon(!selected); if (selected) { frame.setSelected(true); } } } catch (PropertyVetoException e2) { } } }
Example 5
Source File: RuleEditorViews.java From netbeans with Apache License 2.0 | 6 votes |
public RuleEditorViews(RuleEditorPanel ruleEditorPanel) { this.ruleEditorPanel = ruleEditorPanel; updatedOnlyToggleButton = new JToggleButton(new ViewActionSupport.UpdatedOnlyViewAction(this)); updatedOnlyToggleButton.setToolTipText(updatedOnlyToggleButton.getText()); updatedOnlyToggleButton.setText(null); updatedOnlyToggleButton.setSelected(getViewMode() == ViewMode.UPDATED_ONLY); updatedOnlyToggleButton.setFocusable(false); categorizedToggleButton = new JToggleButton(new ViewActionSupport.CategorizedViewAction(this)); categorizedToggleButton.setToolTipText(categorizedToggleButton.getText()); categorizedToggleButton.setText(null); categorizedToggleButton.setSelected(getViewMode() == ViewMode.CATEGORIZED); categorizedToggleButton.setFocusable(false); allToggleButton = new JToggleButton(new ViewActionSupport.AllViewAction(this)); allToggleButton.setToolTipText(allToggleButton.getText()); allToggleButton.setText(null); allToggleButton.setSelected(getViewMode() == ViewMode.ALL); allToggleButton.setFocusable(false); }
Example 6
Source File: JAccessSelectorPanel.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
private WebButtonPopup generatePopupMenu() { WebButtonPopup pm = new WebButtonPopup(this, PopupWay.downCenter); JPanel list = new JPanel(new GridLayout(7, 1)); for (Entry<String, Integer> acc : otherTypes.entrySet()) { JToggleButton jtb = new JToggleButton( acc.getKey().substring(0, 1).toUpperCase() + acc.getKey().substring(1, Math.min(acc.getKey().length(), 7))); jtb.setSelected((visibility & acc.getValue()) != 0); jtb.addActionListener(e -> { if ((visibility & acc.getValue()) != 0) { visibility -= acc.getValue(); } else { visibility |= acc.getValue(); } }); jtb.setFont(new Font(jtb.getFont().getName(), Font.PLAIN, 10)); list.add(jtb); } pm.setContent(list); return pm; }
Example 7
Source File: ItemDetailPanel.java From osrsclient with GNU General Public License v2.0 | 5 votes |
private void setup() { setLayout(new MigLayout("ins 0,align center, ")); setBackground(new Color(51, 51, 51)); setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); wtbButton = new JToggleButton("WTB"); wtsButton = new JToggleButton("WTS"); wtbButton.setSelected(true); wtsButton.setSelected(true); itemSelectedLabel = new JLabel(); itemSelectedLabel.setMaximumSize(new Dimension(160, 50)); offerModel = new OfferModel(); offerTable = new JTable(offerModel); //Setting up ideal column widths offerTable.getColumnModel().getColumn(0).setPreferredWidth(17); offerTable.getColumnModel().getColumn(1).setPreferredWidth(50); offerTable.getColumnModel().getColumn(3).setPreferredWidth(110); listScroller = new JScrollPane(offerTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); add(wtbButton, "cell 0 2,gapy 0"); add(wtsButton, "cell 1 2, align right, spanx"); add(new JLabel("Item:"), "cell 0 5, gapy 0, align left "); add(itemSelectedLabel, "cell 1 5, gapy 0, align left"); add(listScroller, "cell 0 4,width 100%,height 100%,spanx"); }
Example 8
Source File: PopupAction.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates the popup, calculates position and sets focus */ private void showPopup(Component source) { actionSource = source; actionSource.addComponentListener(this); if (actionSource instanceof JToggleButton) { JToggleButton toggleSource = (JToggleButton) actionSource; toggleSource.setSelected(true); } containingWindow = SwingUtilities.windowForComponent(actionSource); containingWindow.addComponentListener(this); Point position = calculatePosition(source); popupComponent.setLocation(position); popupComponent.setVisible(true); popup = new ContainerPopupDialog(containingWindow, popupComponent, position); popup.setVisible(true); popup.requestFocus(); popupComponent.startTracking(containingWindow); if (propertyChangeListener != null) { popupComponent.getComponent().removePropertyChangeListener(PACK_EVENT, propertyChangeListener); } propertyChangeListener = e -> { if (popup != null) { popup.pack(); // best position may change due to changed dimensions, recalculate and set Point popupPosition = calculatePosition(source); popup.setLocation(popupPosition); } }; popupComponent.getComponent().addPropertyChangeListener(PACK_EVENT, propertyChangeListener); }
Example 9
Source File: PaletteUI.java From pumpernickel with MIT License | 5 votes |
/** * Iterate over every button in this palette and update its selected * state based on whether it matches the currently selected color. */ protected void refreshSelectedStates() { Color c = palette.getColorSelectionModel().getSelectedColor(); for (Component z : palette.getComponents()) { JToggleButton b = (JToggleButton) z; Color f = b.getForeground(); if (f == null) { b.setSelected(false); } else { b.setSelected(f.equals(c)); } } }
Example 10
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 11
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 12
Source File: ShortcutOptionsPanel.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Set the toggle button for a column. * * @param list List of checkboxes. * @param line Line number. * @param value Checkbox value. */ private void setToggleButton(List<? extends JToggleButton> list, int line, boolean value) { if (list == null) { return; } if ((line < 0) || (line >= list.size())) { return; } JToggleButton chk = list.get(line); if (chk == null) { return; } chk.setSelected(value); }
Example 13
Source File: TableInternalFrame.java From chipster with MIT License | 5 votes |
/** * Selects a button from the list and deselects other * buttons in the list * @param selected the selected button * @param buttons button list */ private static void selectButton(JToggleButton selected, Collection<JToggleButton> buttons) { for (JToggleButton button : buttons) { if (button == selected) { button.setSelected(true); } else { button.setSelected(false); } } }
Example 14
Source File: PopupAction.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Hides the popup component. */ private boolean hidePopup() { if (actionSource instanceof JToggleButton) { JToggleButton toggleSource = (JToggleButton) actionSource; toggleSource.setSelected(false); } if (containingWindow != null) { containingWindow.removeComponentListener(this); containingWindow.requestFocusInWindow(); containingWindow = null; } if (actionSource != null) { actionSource.removeComponentListener(this); actionSource = null; } // Check if popup is visible if (popup != null) { popupComponent.setVisible(false); popupComponent.stopTracking(); popupComponent.getComponent().removePropertyChangeListener(PACK_EVENT, propertyChangeListener); // hide popup and reset popup.dispose(); popup = null; hideTime = System.currentTimeMillis(); return true; } return false; }
Example 15
Source File: ToolbarButtonCornerRadius.java From radiance with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates the main frame for <code>this</code> sample. */ public ToolbarButtonCornerRadius() { super("Toolbar button corner radius"); this.setLayout(new BorderLayout()); JToolBar toolBar = new JToolBar(""); toolBar.add(new JLabel("Sample toolbar")); toolBar.add(new JSeparator(SwingConstants.VERTICAL)); JToggleButton buttonDefault = new JToggleButton("radius default"); buttonDefault.setSelected(true); toolBar.add(buttonDefault); JToggleButton button1 = new JToggleButton("radius 5"); // set corner radius to 5 pixels SubstanceCortex.ComponentScope.setToolbarButtonCornerRadius(button1, 5.0f); button1.setSelected(true); toolBar.add(button1); JToggleButton button2 = new JToggleButton("radius 0"); // set corner radius to 0 pixels (perfect rectangle) SubstanceCortex.ComponentScope.setToolbarButtonCornerRadius(button2, 0.0f); button2.setSelected(true); toolBar.add(button2); this.add(toolBar, BorderLayout.NORTH); this.setSize(400, 200); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
Example 16
Source File: DrawingViewPlacardPanel.java From openAGV with Apache License 2.0 | 5 votes |
/** * Creates a new instance. * * @param drawingView The drawing view. */ public DrawingViewPlacardPanel(OpenTCSDrawingView drawingView) { requireNonNull(drawingView, "drawingView"); setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.zoomComboBox = zoomComboBox(drawingView); this.add(zoomComboBox); this.add(zoomViewToWindowButton(drawingView)); // Show/hide grid JToggleButton toggleConstrainerButton = toggleConstrainerButton(drawingView); toggleConstrainerButton.setSelected(drawingView.isConstrainerVisible()); this.add(toggleConstrainerButton); // Show/hide rulers toggleRulersButton = toggleRulersButton(); this.add(toggleRulersButton); // Show/hide leabels JToggleButton toggleLabelsButton = toggleLabelsButton(drawingView); toggleLabelsButton.setSelected(drawingView.isLabelsVisible()); this.add(toggleLabelsButton); // Show/hide blocks JToggleButton toggleBlocksButton = toggleBlocksButton(drawingView); toggleBlocksButton.setSelected(drawingView.isBlocksVisible()); this.add(toggleBlocksButton); }
Example 17
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 18
Source File: Controler.java From brModelo with GNU General Public License v3.0 | 5 votes |
public void PopuleBarra(JComponent obj) { ButtonGroup buttons = new ButtonGroup(); Barra = obj; Acao ac = new Acao(editor, "?", "Controler.interface.BarraLateral.Nothing.img", "Controler.interface.BarraLateral.Nothing.Texto", null); JToggleButton btn = arrume(new JToggleButton(ac)); buttons.add(btn); obj.add(btn); btn.setSelected(true); ac.IDX = -1; this.BtnNothing = btn; int i = 0; for (ConfigAcao ca : Lista) { if (ca.tipo == TipoConfigAcao.tpBotoes || ca.tipo == TipoConfigAcao.tpAny) { ac = new Acao(editor, ca.texto, ca.ico, ca.descricao, ca.command); ac.IDX = i++; btn = arrume(new JToggleButton(ac)); buttons.add(btn); //obj.add(btn); listaBotoes.put(ca.command, btn); } } menuComandos c = menuComandos.cmdDel; String str = "Controler.comandos." + c.toString().substring(3).toLowerCase(); ac = new Acao(editor, Editor.fromConfiguracao.getValor(str + ".descricao"), str + ".img", str + ".descricao", c.toString()); ListaDeAcoesEditaveis.add(ac); ac.normal = false; JButton btn2 = new JButton(ac); btn2.setHideActionText(true); btn2.setFocusable(false); btn2.setPreferredSize(new Dimension(40, 40)); obj.add(btn2); LayoutManager la = obj.getLayout(); if (la instanceof GridLayout) { ((GridLayout) la).setRows(i + 2); } }
Example 19
Source File: FiltersDescriptor.java From netbeans with Apache License 2.0 | 4 votes |
public void assureButtonSelected(boolean selected) { JToggleButton toggleButton = toggleButtonRef.get(); if (toggleButton != null) { toggleButton.setSelected(selected); } }
Example 20
Source File: JAccessSelectorPanel.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
private WebButtonPopup generatePopupMenu() { WebButtonPopup pm = new WebButtonPopup(this, PopupWay.downCenter); JToggleButton pub = new JToggleButton(TreeCellRenderer.mpub); pub.setToolTipText("public"); JToggleButton pri = new JToggleButton(TreeCellRenderer.mpri); pri.setToolTipText("private"); JToggleButton pro = new JToggleButton(TreeCellRenderer.mpro); pro.setToolTipText("protected"); JToggleButton def = new JToggleButton(TreeCellRenderer.mdef); def.setToolTipText("none"); pub.addActionListener(e -> { pub.setSelected(true); pri.setSelected(false); pro.setSelected(false); def.setSelected(false); updateVisibility(ACC_PUBLIC); }); pri.addActionListener(e -> { pub.setSelected(false); pri.setSelected(true); pro.setSelected(false); def.setSelected(false); updateVisibility(ACC_PRIVATE); }); pro.addActionListener(e -> { pub.setSelected(false); pri.setSelected(false); pro.setSelected(true); def.setSelected(false); updateVisibility(ACC_PROTECTED); }); def.addActionListener(e -> { pub.setSelected(false); pri.setSelected(false); pro.setSelected(false); def.setSelected(true); updateVisibility(0); }); switch (visibility) { case ACC_PUBLIC: pub.setSelected(true); break; case ACC_PRIVATE: pri.setSelected(true); break; case ACC_PROTECTED: pro.setSelected(true); break; default: def.setSelected(true); break; } JPanel list = new JPanel(new GridLayout(4, 1)); list.add(pub); list.add(pri); list.add(pro); list.add(def); pm.setContent(list); return pm; }