Java Code Examples for javax.swing.JLabel.getLabelFor()

The following are Jave code examples for showing how to use getLabelFor() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jdk8u-jdk   File: TestObject.java   Source Code and License Vote up 6 votes
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example 2
Project: openjdk-jdk10   File: TestObject.java   Source Code and License Vote up 6 votes
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example 3
Project: openjdk-jdk10   File: SelectAllFilesFilterTest.java   Source Code and License Vote up 6 votes
private static JComboBox findComboBox(Component comp) {

        if (comp instanceof JLabel) {
            JLabel label = (JLabel) comp;
            if (LABEL_TEXT.equals(label.getText())) {
                return (JComboBox) label.getLabelFor();
            }
        }

        if (comp instanceof Container) {
            Container cont = (Container) comp;
            for (int i = 0; i < cont.getComponentCount(); i++) {

                JComboBox result = findComboBox(cont.getComponent(i));
                if (result != null) {
                    return result;
                }
            }
        }

        return null;
    }
 
Example 4
Project: incubator-netbeans   File: Util.java   Source Code and License Vote up 5 votes
public static void hideLabelAndLabelFor(JComponent component, String lab) {
    JLabel label = findLabel(component, lab);
    if (label != null) {
        label.setVisible(false);
        Component c = label.getLabelFor();
        if (c != null) {
            c.setVisible(false);
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: Util.java   Source Code and License Vote up 5 votes
public static void hideLabelAndLabelFor(JComponent component, String lab) {
    JLabel label = findLabel(component, lab);
    if (label != null) {
        label.setVisible(false);
        Component c = label.getLabelFor();
        if (c != null) {
            c.setVisible(false);
        }
    }
}