Java Code Examples for javax.swing.JComponent#getParent()

The following examples show how to use javax.swing.JComponent#getParent() . 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: MemorySamplerViewSupport.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void activateSearch() {
    JComponent panel = getBottomPanel();

    if (searchPanel == null) {
        searchPanel = SearchUtils.createSearchPanel(table);
        panel.add(searchPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }

    panel.setVisible(true);

    searchPanel.setVisible(true);
    searchPanel.requestFocusInWindow();
}
 
Example 2
Source File: RootPaneNoFrameState.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isInState(JComponent c) {
    Component parent = c.getParent();

    if (true)
        return ((JRootPane) c).getWindowDecorationStyle() == JRootPane.NONE;

    if (parent instanceof JFrame)
        return true;

    if (parent instanceof JInternalFrame)
        return true;

    if (parent instanceof JDialog)
        return true;

    return false;
}
 
Example 3
Source File: QuickActionMenu.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add specific menu items for a given component.
 *
 * @param comp The specific {@code JComponent}.
 * @return This {@code QuickActionMenu}.
 */
public QuickActionMenu addMenuItems(JComponent comp) {
    if (comp instanceof UnitLabel) {
        createUnitMenu((UnitLabel)comp);
    } else if (comp instanceof GoodsLabel) {
        createGoodsMenu((GoodsLabel)comp);
    } else if (comp instanceof MarketLabel) {
        createMarketMenu((MarketLabel)comp);
    } else if (comp instanceof ASingleTilePanel) {
        createTileMenu((ASingleTilePanel)comp);
    } else if (comp.getParent() instanceof ASingleTilePanel) {
        // Also check the parent to show the popup in the
        // center of the colony panel tile.
        createTileMenu((ASingleTilePanel)comp.getParent());
    }
    return this;
}
 
Example 4
Source File: MemoryView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void activateSearch() {
    JComponent panel = getBottomPanel();
    
    if (searchPanel == null) {
        searchPanel = SearchUtils.createSearchPanel(table);
        panel.add(searchPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    searchPanel.setVisible(true);
    searchPanel.requestFocusInWindow();
}
 
Example 5
Source File: ThreadsCPUView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void activateFilter() {
    JComponent panel = getBottomPanel();
    
    if (filterPanel == null) {
        filterPanel = FilterUtils.createFilterPanel(table, null);
        panel.add(filterPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    filterPanel.setVisible(true);
    filterPanel.requestFocusInWindow();
}
 
Example 6
Source File: DataView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void activateFilter() {
    JComponent panel = getBottomPanel();
    
    if (filterPanel == null) {
        filterPanel = FilterUtils.createFilterPanel(getResultsComponent(), getExcludesFilter(), getFilterOptions());
        panel.add(filterPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    filterPanel.setVisible(true);
    filterPanel.requestFocusInWindow();
}
 
Example 7
Source File: MemoryView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void activateSearch() {
    JComponent panel = getBottomPanel();
    
    if (searchPanel == null) {
        searchPanel = SearchUtils.createSearchPanel(table);
        panel.add(searchPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    searchPanel.setVisible(true);
    searchPanel.requestFocusInWindow();
}
 
Example 8
Source File: CursorUtil.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
private static JDialog findContainingDialog(JComponent component) {
	Container container = component.getParent();

	while (container != null) {
		if (container instanceof JDialog) {
			return (JDialog) container;
		}

		container = container.getParent();
	}

	return null;
}
 
Example 9
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * @see javax.swing.plaf.ComponentUI#update(java.awt.Graphics, javax.swing.JComponent)
 */
public void update(Graphics g, JComponent c) {
    SeaGlassContext context = getContext(c);

    SeaGlassLookAndFeel.update(context, g);
    if (((JRootPane) c).getWindowDecorationStyle() != JRootPane.NONE) {
        context.getPainter().paintRootPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight());
    } else if (PlatformUtils.isMac()) {
        // We may need to paint the rootpane on a Mac if the window is
        // decorated.
        boolean   shouldPaint       = false;
        Container toplevelContainer = c.getParent();

        if (toplevelContainer instanceof JFrame) {
            shouldPaint = !((JFrame) toplevelContainer).isUndecorated();
        }

        if (shouldPaint) {
            if (!paintTextured) {
                g.setColor(c.getBackground());
                g.fillRect(0, 0, c.getWidth(), c.getHeight());
            } else if (isWindowFocused.isInState(c)) {
                contentActive.paint((Graphics2D) g, c, c.getWidth(), c.getHeight());
            } else {
                contentInactive.paint((Graphics2D) g, c, c.getWidth(), c.getHeight());
            }
        }
    }

    paint(context, g);
    context.dispose();
}
 
Example 10
Source File: RadioButtonUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public synchronized void paint(Graphics g, JComponent c) {
	// without this, checkboxes and radio buttons have a fixed bg color instead of using the bg
	// color of the container they are in
	if (c.getParent() != null) {
		c.setBackground(c.getParent().getBackground());
	}
	super.paint(g, c);
}
 
Example 11
Source File: CssStylesTC.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setContent(JComponent component) {
    if(component.getParent() == null) {
        //not shown
        removeAll();
        add(component, BorderLayout.CENTER);
        revalidate();
        repaint();
    }
}
 
Example 12
Source File: SpinnerNextButtonPainter.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void paintButton(Graphics2D g, JComponent c, int width, int height) {
    boolean useToolBarColors = isInToolBar(c);
    Shape s;

    JSpinner spinner = (JSpinner) c.getParent();
    boolean editorFocused = false;
    JComponent editor = spinner.getEditor();
    if (editor instanceof DefaultEditor) {
        editorFocused = ((DefaultEditor)editor).getTextField().isFocusOwner();
    }
    if (focused || editorFocused) {
        s = createButtonShape(0, 0, width, height, CornerSize.OUTER_FOCUS);
        g.setPaint(getFocusPaint(s, FocusType.OUTER_FOCUS, useToolBarColors));
        g.fill(s);

        s = createButtonShape(0, 1, width - 1, height - 1, CornerSize.INNER_FOCUS);
        g.setPaint(getFocusPaint(s, FocusType.INNER_FOCUS, useToolBarColors));
        g.fill(s);
    }

    s = createButtonShape(0, 2, width - 2, height - 2, CornerSize.BORDER);
    g.setPaint(getSpinnerNextBorderPaint(s, type));
    g.fill(s);

    s = createButtonShape(1, 3, width - 4, height - 4, CornerSize.INTERIOR);
    g.setPaint(getSpinnerNextInteriorPaint(s, type));
    g.fill(s);
}
 
Example 13
Source File: StyledToolTipUI.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paint(Graphics g, JComponent tooltip) {
	// Get rid of popup borders, if it has any (Heavy weight popups tend to
	// pack the tooltip in a JPanel
	Container parent = tooltip.getParent();
	if (parent instanceof JComponent) {
		JComponent popup = (JComponent) parent;
		if (popup.getBorder() != null) {
			popup.setBorder(null);
		}
	}
	super.paint(g, tooltip);
}
 
Example 14
Source File: SearchPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the given component in the main area of the layout.
 * 
 * @param component component to show.
 */
private void showComponent(JComponent component) {
    if (component.getParent() == null) {
        JComponent shownComponent = (component == messageLabel) ? searchPanel : messageLabel;
        ((GroupLayout)getLayout()).replace(shownComponent, component);
    }
}
 
Example 15
Source File: SearchPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the given component in the main area of the layout.
 * 
 * @param component component to show.
 */
private void showComponent(JComponent component) {
    if (component.getParent() == null) {
        JComponent shownComponent = (component == messageLabel) ? searchPanel : messageLabel;
        ((GroupLayout)getLayout()).replace(shownComponent, component);
    }
}
 
Example 16
Source File: SystemAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Create an icon.
* @param comp a component, which must be unattached to a container
*             and should not be used for other purposes
*/
public ComponentIcon(JComponent comp) {
    if (comp.getParent() != null) {
        throw new IllegalArgumentException();
    }

    this.comp = comp;

    Dimension size = comp.getPreferredSize();

    // Careful! If you have e.g. a JLabel with empty text, width = 0 => exceptions.
    // Must make sure it is at least a reasonable size.
    comp.setSize(Math.max(size.width, 16), Math.max(size.height, 16));
}
 
Example 17
Source File: SpinnerPreviousButtonPainter.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void paintButton(Graphics2D g, JComponent c, int width, int height) {
    boolean useToolBarColors = isInToolBar(c);
    Shape s;

    JSpinner spinner = (JSpinner) c.getParent();
    boolean editorFocused = false;
    JComponent editor = spinner.getEditor();
    if (editor instanceof DefaultEditor) {
        editorFocused = ((DefaultEditor)editor).getTextField().isFocusOwner();
    }
    if (focused || editorFocused) {
        s = createButtonShape(0, 0, width, height, CornerSize.OUTER_FOCUS);
        g.setPaint(getFocusPaint(s, FocusType.OUTER_FOCUS, useToolBarColors));
        g.fill(s);

        s = createButtonShape(0, 0, width - 1, height - 1, CornerSize.INNER_FOCUS);
        g.setPaint(getFocusPaint(s, FocusType.INNER_FOCUS, useToolBarColors));
        g.fill(s);
    }

    s = createButtonShape(0, 0, width - 2, height - 2, CornerSize.BORDER);
    g.setPaint(getSpinnerPrevBorderPaint(s, type));
    g.fill(s);

    s = createButtonShape(1, 1, width - 4, height - 4, CornerSize.INTERIOR);
    g.setPaint(getSpinnerPrevInteriorPaint(s, type));
    g.fill(s);

    s = shapeGenerator.createRectangle(1, 0, width - 4, 1);
    g.setPaint(getSpinnerPrevTopLinePaint(s, type));
    g.fill(s);
}
 
Example 18
Source File: ToggleButtonUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize(JComponent c) {
	if (c.getParent() instanceof JToolBar) {
		return new Dimension((int) super.getPreferredSize(c).getWidth() + 6,
				(int) super.getPreferredSize(c).getHeight() + 6);
	} else {
		return new Dimension((int) super.getPreferredSize(c).getWidth() + 10, (int) super.getPreferredSize(c)
				.getHeight() + 6);
	}
}
 
Example 19
Source File: ComboBoxArrowButtonEditableState.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isInState(JComponent c) {
    Component parent = c.getParent();

    return parent instanceof JComboBox && ((JComboBox) parent).isEditable();
}
 
Example 20
Source File: ProgressBarUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void paintDeterminate(Graphics g, JComponent c) {
	boolean compressed = Boolean.parseBoolean(String.valueOf(progressBar
			.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));

	int y = 0;
	int x = 0;
	int w;
	int h;
	if (compressed) {
		x = (int) (c.getWidth() * 0.67);
		w = (int) (c.getWidth() * 0.33);
		y = 3;
		h = c.getHeight() - 6;
	} else {
		w = c.getWidth();
		h = c.getHeight() / 2;
	}

	int amountFull = getAmountFull(progressBar.getInsets(), w, h);

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (c.isOpaque()) {
		if (c.getParent() != null) {
			g2.setColor(c.getParent().getBackground());
		} else {
			g2.setColor(c.getBackground());
		}
		g2.fillRect(x, y, c.getWidth(), c.getHeight());
	}

	g2.setColor(Colors.PROGRESSBAR_BACKGROUND);
	g2.fillRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	g2.setColor(Colors.PROGRESSBAR_BORDER);
	g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	Paint gp = new GradientPaint(x, y + 3, Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_START, x, h - 5,
			Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_END);
	g2.setPaint(gp);
	g2.fillRoundRect(x + 3, y + 3, amountFull - 5, h - 5, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);

	drawString(g2, w, h, compressed);
}