Java Code Examples for javax.swing.JComponent.getSize()

The following are Jave code examples for showing how to use getSize() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: MultiDiffPanelController.java   View Source Code Vote up 6 votes
private void updateSplitLocation () {
    JComponent parent = (JComponent) panel.getParent();
    Dimension dim = parent == null ? new Dimension() : parent.getSize();
    if (dim.width <= 0 || dim.height <= 0) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                updateSplitLocation();
            }
        });
        return;
    }
    FileViewComponent fileComp = getActiveFileComponent();
    int preferredHeaderHeight = fileComp.getPreferredHeaderHeight();
    int preferredHeight = fileComp.getPreferredHeight();
    int optimalLocation = preferredHeight + preferredHeaderHeight + 5;
    if (optimalLocation > dim.height / 3) {
        optimalLocation = dim.height / 3;
    }
    if (optimalLocation <= preferredHeaderHeight) {
        optimalLocation = preferredHeaderHeight * 3;
    }
    if (dividerSet && panel.splitPane.getDividerLocation() <= optimalLocation) return;
    panel.splitPane.setDividerLocation(optimalLocation);
    dividerSet = true;
}
 
Example 2
Project: incubator-netbeans   File: ComponentMorpher2.java   View Source Code Vote up 6 votes
private Image getComponentImage(JComponent component) {
    // Initial component sizing & layout
    component.setSize((getClientSize().width == 0) ? component.getPreferredSize() : getClientSize()); // try to fit the component to ComponentMorpher
    component.doLayout(); // layout component

    // Correct component sizing & layout
    component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
    component.doLayout(); // layout component

    // One more iteration because of nested JTextAreas
    component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
    component.doLayout(); // layout component

    // Paint component into BufferedImage
    BufferedImage componentImage = new BufferedImage(component.getSize().width, component.getSize().height,
                                                     BufferedImage.TYPE_INT_RGB);
    component.printAll(componentImage.getGraphics());

    return componentImage;
}
 
Example 3
Project: incubator-netbeans   File: AquaSeparatorUI.java   View Source Code Vote up 5 votes
public void paint( Graphics g, JComponent c ) {
    Dimension s = c.getSize();

    if (((JSeparator) c).getOrientation() == JSeparator.HORIZONTAL) {
        g.setColor(lineColorHorizontal);
        g.drawLine(1, 5, s.width - 2, 5);
    } else {
        g.setColor(lineColorVertical);
        g.drawLine(0, 1, 0, s.height - 2);
    }
}
 
Example 4
Project: Invasion   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 5
Project: AquamarineLake   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 6
Project: AquamarineLake   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 7
Project: COE1186   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 8
Project: COE1186   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 9
Project: COE1186   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 10
Project: rapidminer   File: ComboBoxUI.java   View Source Code Vote up 4 votes
/**
 * Draws the combobox itself.
 */
private void paintBox(Graphics g, JComponent c) {
	int w = c.getWidth();
	int h = c.getHeight() - 1;
	if (w <= 0 || h <= 0) {
		return;
	}

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

	if (c.isEnabled()) {
		if (Boolean.parseBoolean(String.valueOf(c.getClientProperty(RapidLookTools.PROPERTY_INPUT_BACKGROUND_DARK)))) {
			g2.setColor(Colors.COMBOBOX_BACKGROUND_DARK);
		} else {
			g2.setColor(Colors.COMBOBOX_BACKGROUND);
		}
	} else {
		g2.setColor(Colors.COMBOBOX_BACKGROUND_DISABLED);
	}

	g2.fillRoundRect(0, 0, w - 1, h, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	// arrow
	int ny = c.getSize().height / 2 - 3;
	int nx = c.getWidth() - 15;

	if (isDown && c.isEnabled()) {
		nx++;
		ny++;
	}
	g2.translate(nx, ny);

	if (c.isEnabled()) {
		g2.setColor(Colors.COMBOBOX_ARROW);
	} else {
		g2.setColor(Colors.COMBOBOX_ARROW_DISABLED);
	}

	w = 14;
	Polygon arrow = new Polygon(new int[] { 0, 4, 8 }, new int[] { 0, 6, 0 }, 3);
	g2.fillPolygon(arrow);

	g2.translate(-nx, -ny);
}