Java Code Examples for javax.swing.JButton#isEnabled()

The following examples show how to use javax.swing.JButton#isEnabled() . 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: TubesProjectConfigPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {

        JButton upBtn = client ? upBtnClient : upBtnService;
        int selectedRow = getSelectedRow(client);
        if (selectedRow == 0) {
            upBtn.setEnabled(false);
        } else {
            if (!upBtn.isEnabled()) {
                upBtn.setEnabled(true);
            }
        }

        TubeTableModel tModel = client ? tubeTableClientModel : tubeTableServiceModel;
        JButton downBtn = client ? downBtnClient : downBtnService;
        if (selectedRow == tModel.getRowCount() - 1) {
            downBtn.setEnabled(false);
        } else {
            if (!downBtn.isEnabled()) {
                downBtn.setEnabled(true);
            }
        }
    }
}
 
Example 2
Source File: SwingUtils.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Performs a click on the button labelled with the specified text.
 * @param window
 *  The window containing the button.
 * @param buttonText
 *  The button's label.
 * @return
 *  true if the button was found;  false if the button was not found
 */
static boolean clickButton(final Window window, final String buttonText) {
    final JButton button = findButton(window, buttonText);
    if (button == null) return false;

    if (! button.isEnabled()) {
        button.setEnabled(true);
        Utils.logToConsole("Button was disabled, has been enabled: " + buttonText);
    }

    Utils.logToConsole("Click button: " + buttonText);
    button.doClick();
    if (! button.isEnabled()) Utils.logToConsole("Button now disabled: " + buttonText);
    return true;
}
 
Example 3
Source File: EditablePropertyDisplayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void trySendEnterToDialog() {
    //        System.err.println("SendEnterToDialog");
    EventObject ev = EventQueue.getCurrentEvent();

    if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) {
        if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
            return;
        }

        if (
            ev.getSource() instanceof JTextComponent &&
                ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
                ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
        ) {
            return;
        }

        JRootPane jrp = getRootPane();

        if (jrp != null) {
            JButton b = jrp.getDefaultButton();

            if ((b != null) && b.isEnabled()) {
                b.doClick();
            }
        }
    }
}
 
Example 4
Source File: BaseTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void trySendEnterToDialog(BaseTable bt) {
    //        System.err.println("SendEnterToDialog");
    EventObject ev = EventQueue.getCurrentEvent();

    if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) {
        if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
            return;
        }

        if (
            ev.getSource() instanceof JTextComponent &&
                ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
                ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
        ) {
            return;
        }

        JRootPane jrp = bt.getRootPane();

        if (jrp != null) {
            JButton b = jrp.getDefaultButton();

            if ((b != null) && b.isEnabled()) {
                b.doClick();
            }
        }
    }
}
 
Example 5
Source File: ETable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    JRootPane jrp = getRootPane();
    if (jrp != null) {
        JButton b = getRootPane().getDefaultButton();
        if (b != null && b.isEnabled()) {
            b.doClick();
        }
    }
}
 
Example 6
Source File: JSimpleColorPicker.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
private Border getBorderInner(JButton jButton) {
	if (jButton.isEnabled()) {
		return BorderFactory.createLineBorder(Color.BLACK, 1);
	} else {
		return BorderFactory.createLineBorder(Color.DARK_GRAY, 1);
	}
}
 
Example 7
Source File: SwingUtils.java    From ib-controller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Performs a click on the button labelled with the specified text.
 * @param window
 *  The window containing the button.
 * @param buttonText
 *  The button's label.
 * @return
 *  true if the button was found;  false if the button was not found
 */
static boolean clickButton(final Window window, final String buttonText) {
    final JButton button = findButton(window, buttonText);
    if (button == null) return false;

    if (! button.isEnabled()) {
        button.setEnabled(true);
        Utils.logToConsole("Button was disabled, has been enabled: " + buttonText);
    }

    Utils.logToConsole("Click button: " + buttonText);
    button.doClick();
    if (! button.isEnabled()) Utils.logToConsole("Button now disabled: " + buttonText);
    return true;
}
 
Example 8
Source File: CellTypeTextFieldDefaultImpl.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates a {@link JFormattedTextField} for the specified cell. If a formatter is given, will
 * apply it to the field. Does not validate the model, so make sure this call works!
 * 
 * @param model
 * @param rowIndex
 * @param columnIndex
 * @param cellClass
 * @param formatter
 *            the formatter or <code>null</code> if none is required
 * @param hideUnavailableContentAssist
 * @return
 */
public CellTypeTextFieldDefaultImpl(final TablePanelModel model, final int rowIndex, final int columnIndex,
		final Class<? extends CellType> cellClass, AbstractFormatter formatter, boolean hideUnavailableContentAssist) {
	super();

	final JFormattedTextField field = CellTypeImplHelper.createFormattedTextField(model, rowIndex, columnIndex);
	setLayout(new BorderLayout());
	add(field, BorderLayout.CENTER);

	// otherwise 'null' would be restored
	Object value = model.getValueAt(rowIndex, columnIndex);
	String text = value != null ? String.valueOf(value) : "";

	// specical handling when formatter is given
	if (formatter != null) {
		field.setFormatterFactory(new DefaultFormatterFactory(formatter));
	}
	field.setText(text);

	// set syntax assist if available
	String syntaxHelp = model.getSyntaxHelpAt(rowIndex, columnIndex);
	if (syntaxHelp != null && !"".equals(syntaxHelp.trim())) {
		SwingTools.setPrompt(syntaxHelp, field);
	}

	// see if content assist is possible for this field, if so add it
	ImageIcon icon = SwingTools.createIcon("16/"
			+ I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.action.content_assist.icon"));
	JButton contentAssistButton = new JButton();
	contentAssistButton.setIcon(icon);
	if (field.isEnabled() && model.isContentAssistPossibleForCell(rowIndex, columnIndex)) {
		contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),
				"gui.action.content_assist_enabled.tip"));
		CellTypeImplHelper.addContentAssist(model, rowIndex, columnIndex, field, contentAssistButton, cellClass);
	} else {
		contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),
				"gui.action.content_assist_disabled.tip"));
		contentAssistButton.setEnabled(false);
	}
	if (contentAssistButton.isEnabled() || (!contentAssistButton.isEnabled() && !hideUnavailableContentAssist)) {
		add(contentAssistButton, BorderLayout.EAST);
	}

	// set size so panels don't grow larger when they get the chance
	setPreferredSize(new Dimension(300, 20));
	setMinimumSize(new Dimension(100, 15));
	setMaximumSize(new Dimension(1600, 30));
}
 
Example 9
Source File: SwingUtils.java    From IBC with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Indicates whether the specified JButton is enabled.
 * @param window
 * the window in which to search for the required JButton
 * @param buttonText
 * the label of the required JButton
 * @return
 * true if the JButton is enabled; false if there is no such JButton, or it
 * is disabled
 */
static boolean isButtonEnabled(final Window window, final String buttonText) {
    final JButton button = findButton(window, buttonText);
    if (button == null) return false;

    return button.isEnabled();
}
 
Example 10
Source File: SwingUtils.java    From ib-controller with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Indicates whether the specified JButton is enabled.
 * @param window
 * the window in which to search for the required JButton
 * @param buttonText
 * the label of the required JButton
 * @return
 * true if the JButton is enabled; false if there is no such JButton, or it
 * is disabled
 */
static boolean isButtonEnabled(final Window window, final String buttonText) {
    final JButton button = findButton(window, buttonText);
    if (button == null) return false;

    return button.isEnabled();
}