Java Code Examples for javax.swing.JToggleButton#isSelected()

The following examples show how to use javax.swing.JToggleButton#isSelected() . 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: LogTableManager.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
    Object o = e.getSource();
    if (o instanceof JToggleButton) {
        JToggleButton b = (JToggleButton) o;
        if (b.isSelected()) {
            if (!autoFollowScroll) {
                scrollToBottom();
            }
            autoFollowScroll = true;
        } else {
            autoFollowScroll = false;
        }
    }

}
 
Example 2
Source File: VehicleCommanderJFrame.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private void jToggleButton_openAnalysisToolbarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton_openAnalysisToolbarActionPerformed
    boolean visible = jToggleButton_openAnalysisToolbar.isSelected();
    jPanel_mainToolbar.setVisible(visible);
    if (!visible) {
        //See if one of the tools in this bar is active. If so, deactivate it.
        Component[] components = jPanel_mainToolbar.getComponents();
        for (Component c : components) {
            if (c instanceof JToggleButton) {
                JToggleButton button = (JToggleButton) c;
                if (button.isSelected()) {
                    jToggleButton_deactivateAllTools.setSelected(true);
                    break;
                }
            }
        }
    }
}
 
Example 3
Source File: ToggleButtonGroup.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	for (JToggleButton button : primaryButtons) {
		if (button != e.getSource() && button.isSelected()) {
			button.setSelected(false);
		} else if (button == e.getSource() && !button.isSelected()) {
			button.setSelected(true);
		}

		if (button.isSelected()) {
			button.setFont(button.getFont().deriveFont(Font.BOLD));
		} else {
			button.setFont(button.getFont().deriveFont(Font.PLAIN));
		}
	}

	if (secondaryButton != null) {
		if (secondaryButton != e.getSource() && secondaryButton.isSelected()) {
			secondaryButton.clearMenuSelection();
		}
	}
}
 
Example 4
Source File: SeaGlassDesktopIconUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
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: GatewayLoginFrameHandler.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void switchToFIX(Window window) throws IbcException {
    JToggleButton button = SwingUtils.findToggleButton(window, "FIX CTCI");
    if (button == null) throw new IbcException("FIX CTCI selector");
    
    if (! button.isSelected()) {
        Utils.logToConsole("Clicking FIX CTCI selector");
        button.doClick();
    }
}
 
Example 6
Source File: GatewayLoginFrameHandler.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void switchToIBAPI(Window window) throws IbcException {
    JToggleButton button = SwingUtils.findToggleButton(window, "IB API");
    if (button == null) button = SwingUtils.findToggleButton(window, "TWS/API") ;
    if (button == null) throw new IbcException("IB API selector");
    
    if (! button.isSelected()) {
        Utils.logToConsole("Clicking FIX CTCI selector");
        button.doClick();
    }
}
 
Example 7
Source File: BreakpointsViewButtons.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    ActiveBreakpoints ab = this.ab;
    if (ab == null || !ab.canDeactivateBreakpoints()) {
        return ;
    }
    JToggleButton button = (JToggleButton) e.getSource();
    final boolean active = !button.isSelected();
    ab.setBreakpointsActive(active);
    setTooltip(button, active, true);
}
 
Example 8
Source File: WindowsPlacesBar.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
protected void doDirectoryChanged(File f) {
    for (int i=0; i<buttons.length; i++) {
        JToggleButton b = buttons[i];
        if (files[i].equals(f)) {
            b.setSelected(true);
            break;
        } else if (b.isSelected()) {
            // Remove temporarily from group because it doesn't
            // allow for no button to be selected.
            buttonGroup.remove(b);
            b.setSelected(false);
            buttonGroup.add(b);
        }
    }
}
 
Example 9
Source File: PaletteUI.java    From pumpernickel with MIT License 5 votes vote down vote up
protected void paintGrid(Graphics2D g, JPalette p) {
	for (Component c : p.getComponents()) {
		Color f = c.getForeground();
		g.setColor(f);
		Rectangle r = c.getBounds();
		g.fillRect(r.x, r.y, r.width, r.height);
		JToggleButton b = (JToggleButton) c;
		if (b.isSelected()) {
			paintSelectedIndicator(g, p, b, r);
		}
	}
}
 
Example 10
Source File: PaletteUI.java    From pumpernickel with MIT License 5 votes vote down vote up
protected JToggleButton getSelectedButton(JPalette palette) {
	for (Component c : palette.getComponents()) {
		if (c instanceof JToggleButton) {
			JToggleButton b = (JToggleButton) c;
			if (b.isSelected())
				return b;
		}
	}
	return null;
}
 
Example 11
Source File: IconPanel.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public String getSelectedName() {
  final Enumeration<AbstractButton> iterator = this.group.getElements();
  while (iterator.hasMoreElements()) {
    final JToggleButton button = (JToggleButton) iterator.nextElement();
    if (button.isSelected()) {
      return button.getName();
    }
  }
  return null;
}
 
Example 12
Source File: TableInternalFrame.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Return a ColumnType depending on which button is pressed. 
 * @return selected column type
 */
public ColumnType getSelectedColumnType(){
	if(markColumnsButtons == null){
		return null;
	}
	for(JToggleButton button : markColumnsButtons.keySet()){
		if(button.isSelected()){
			return markColumnsButtons.get(button);
		}
	}
	return null;
	
}
 
Example 13
Source File: Query.java    From opt4j with MIT License 4 votes vote down vote up
/**
 * Get the current value in the entry with the given name, and return as a
 * String. All entry types support this. Note that this method should be
 * called from the event dispatch thread, since it needs to query to UI
 * widgets for their current values. If it is called from another thread,
 * there is no assurance that the value returned will be the current value.
 * 
 * @param name
 *            The name of the entry.
 * @return The value currently in the entry as a String.
 * @exception NoSuchElementException
 *                If there is no item with the specified name. Note that
 *                this is a runtime exception, so it need not be declared
 *                explicitly.
 * @exception IllegalArgumentException
 *                If the entry type does not have a string representation
 *                (this should not be thrown).
 */
@SuppressWarnings("rawtypes")
public String getStringValue(String name) throws NoSuchElementException, IllegalArgumentException {
	Object result = _entries.get(name);

	if (result == null) {
		throw new NoSuchElementException("No item named \"" + name + " \" in the query box.");
	}

	if (result instanceof JTextField) {
		return ((JTextField) result).getText();
	} else if (result instanceof QueryColorChooser) {
		return ((QueryColorChooser) result).getSelectedColor();
	} else if (result instanceof QueryFileChooser) {
		return ((QueryFileChooser) result).getSelectedFileName();
	} else if (result instanceof JTextArea) {
		return ((JTextArea) result).getText();
	} else if (result instanceof JToggleButton) {
		// JRadioButton and JCheckButton are subclasses of JToggleButton
		JToggleButton toggleButton = (JToggleButton) result;

		if (toggleButton.isSelected()) {
			return "true";
		} else {
			return "false";
		}
	} else if (result instanceof JSlider) {
		return "" + ((JSlider) result).getValue();
	} else if (result instanceof JComboBox) {
		return (String) (((JComboBox) result).getSelectedItem());
	} else if (result instanceof JToggleButton[]) {
		// JRadioButton and JCheckButton are subclasses of JToggleButton
		// Regrettably, ButtonGroup gives no way to determine
		// which button is selected, so we have to search...
		JToggleButton[] buttons = (JToggleButton[]) result;
		StringBuffer toReturn = null;

		for (int i = 0; i < buttons.length; i++) {
			if (buttons[i].isSelected()) {
				if (toReturn == null) {
					toReturn = new StringBuffer(buttons[i].getText());
				} else {
					toReturn.append(", " + buttons[i].getText());
				}
			}
		}

		if (toReturn == null) {
			toReturn = new StringBuffer();
		}

		return toReturn.toString();
	} else if (result instanceof QueryScrollPane) {
		return ((QueryScrollPane) result).getText();
	} else {
		throw new IllegalArgumentException("Query class cannot generate"
				+ " a string representation for entries of type " + result.getClass());
	}
}