Java Code Examples for javax.swing.AbstractButton#getText()

The following examples show how to use javax.swing.AbstractButton#getText() . 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: JMenuItemJavaElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static String getText(String original, Component current, Component[] components) {
    String itemText = original;
    int suffixIndex = 0;
    for (int i = 0; i < components.length; i++) {
        if (components[i] == current) {
            return itemText;
        }
        if (!(components[i] instanceof AbstractButton)) {
            continue;
        }
        AbstractButton menuItem = (AbstractButton) components[i];
        String menuItemText = menuItem.getText();
        if ("".equals(menuItemText) || menuItemText == null) {
            menuItemText = getTextFromIcon((JMenuItem) components[i]);
        }
        if (menuItemText.equals(original)) {
            itemText = String.format("%s(%d)", original, ++suffixIndex);
        }
    }
    return itemText;
}
 
Example 2
Source File: UI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void mnemonicAndToolTip(AbstractButton button, String toolTip) {
    String text = button.getText();

    if (text == null) {
        Mnemonics.setLocalizedText(button, toolTip);
        button.setText(null);
    }
    else {
        Mnemonics.setLocalizedText(button, text);
        button.setText(cutMnemonicAndAmpersand(text));
    }
    button.setToolTipText(cutMnemonicAndAmpersand(toolTip));
}
 
Example 3
Source File: CognizantITSSettings.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private String getSelectedButton(ButtonGroup bGroup) {
    for (Enumeration<AbstractButton> buttons = bGroup.getElements(); buttons.hasMoreElements();) {
        AbstractButton button = buttons.nextElement();
        if (button.isSelected()) {
            return button.getText();
        }
    }
    return "None";
}
 
Example 4
Source File: RapidDockingToolbar.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void installButtonUI(AbstractButton button) {
	button.setUI(new ButtonUI());
	button.setBorder(null);
	button.setMargin(new Insets(0, 0, 0, 0));
	if ((button.getText() == null || "".equals(button.getText())) && button.getIcon() != null) {
		button.setPreferredSize(new Dimension((int) (button.getIcon().getIconWidth() * 1.45d), (int) (button.getIcon()
				.getIconHeight() * 1.45d)));
	}
}
 
Example 5
Source File: AddFrame.java    From JavaMainRepo with Apache License 2.0 5 votes vote down vote up
public String getSelectedRadioButton() {
	for (Enumeration<AbstractButton> allButtons = buttonGroup.getElements(); allButtons.hasMoreElements();) {
		AbstractButton button = allButtons.nextElement();
		if (button.isSelected()) {
			return button.getText();
		}
	}
	return null;
}
 
Example 6
Source File: AddFrame.java    From JavaMainRepo with Apache License 2.0 5 votes vote down vote up
public String getSelectedRadioButton() {
	for (Enumeration<AbstractButton> allButtons = buttonGroup.getElements(); allButtons.hasMoreElements();) {
		AbstractButton button = allButtons.nextElement();
		if (button.isSelected()) {
			return button.getText();
		}
	}
	return null;
}
 
Example 7
Source File: TimeSeriesExportHelper.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static int parseLevel(ButtonGroup buttonGroup) {
    Enumeration<AbstractButton> buttonEnumeration = buttonGroup.getElements();
    while (buttonEnumeration.hasMoreElements()) {
        AbstractButton abstractButton = buttonEnumeration.nextElement();
        if (abstractButton.isSelected()) {
            String buttonText = abstractButton.getText();
            final int index = buttonText.indexOf(" (");
            if (index != -1) {
                buttonText = buttonText.substring(0, index);
            }
            return Integer.parseInt(buttonText);
        }
    }
    return-1;
}
 
Example 8
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getBaseline(javax.swing.JComponent,
 *      int, int)
 */
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }

    if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Width and height must be >= 0");
    }

    AbstractButton b    = (AbstractButton) c;
    String         text = b.getText();

    if (text == null || "".equals(text)) {
        return -1;
    }

    Insets    i        = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();

    viewRect.x      = i.left;
    viewRect.y      = i.top;
    viewRect.width  = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SeaGlassContext context = getContext(b);
    FontMetrics     fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));

    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(),
                                                            b.getVerticalAlignment(), b.getHorizontalTextPosition(),
                                                            b.getVerticalTextPosition(), viewRect, iconRect, textRect,
                                                            b.getIconTextGap());
    View view     = (View) b.getClientProperty(BasicHTML.propertyKey);
    int  baseline;

    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    } else {
        baseline = textRect.y + fm.getAscent();
    }

    context.dispose();
    return baseline;
}