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

The following are Jave code examples for showing how to use getHeight() 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: NimbusViewTabDisplayerUI.java   View Source Code Vote up 6 votes
@Override
protected void paintDisplayerBackground( Graphics g, JComponent c ) {

    int x = 0;
    int y = 0;
    int width = c.getWidth();
    int height = c.getHeight();
    
    Object o = null;
    o = UIManager.get("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter");

    if ((o != null) && (o instanceof javax.swing.Painter)) {
        javax.swing.Painter painter = (javax.swing.Painter) o;
        BufferedImage bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bufIm.createGraphics();
        g2d.setBackground(UIManager.getColor("Panel.background"));
        g2d.clearRect(0, 0, width, height);
        painter.paint(g2d, null, width, height);
        g.drawImage(bufIm, x, y, null);
    }
}
 
Example 2
Project: incubator-netbeans   File: TabListPopupAction.java   View Source Code Vote up 6 votes
@Override
public void actionPerformed(ActionEvent ae) {
    if ("pressed".equals(ae.getActionCommand())) { //NOI18N
        JComponent jc = (JComponent) ae.getSource();
        Point p = new Point(jc.getWidth(), jc.getHeight());
        SwingUtilities.convertPointToScreen(p, jc);
        if (!ButtonPopupSwitcher.isShown()) {
            ButtonPopupSwitcher.showPopup(jc, displayer, p.x, p.y);
        } else {
            ButtonPopupSwitcher.hidePopup();
        }
        //Other portion of issue 37487, looks funny if the
        //button becomes pressed
        if (jc instanceof AbstractButton) {
            AbstractButton jb = (AbstractButton) jc;
            jb.getModel().setPressed(false);
            jb.getModel().setRollover(false);
            jb.getModel().setArmed(false);
            jb.repaint();
        }
    }
}
 
Example 3
Project: incubator-netbeans   File: TabListPopupAction.java   View Source Code Vote up 6 votes
@Override
public void actionPerformed( ActionEvent ae ) {
    if ("pressed".equals(ae.getActionCommand())) { //NOI18N
        JComponent jc = (JComponent) ae.getSource();
        Point p = new Point(jc.getWidth(), jc.getHeight());
        SwingUtilities.convertPointToScreen(p, jc);
        if (!ButtonPopupSwitcher.isShown()) {
            ButtonPopupSwitcher.showPopup(jc, controller, p.x, p.y);
        } else {
            ButtonPopupSwitcher.hidePopup();
        }
        //Other portion of issue 37487, looks funny if the
        //button becomes pressed
        if (jc instanceof AbstractButton) {
            AbstractButton jb = (AbstractButton) jc;
            jb.getModel().setPressed(false);
            jb.getModel().setRollover(false);
            jb.getModel().setArmed(false);
            jb.repaint();
        }
    }
}
 
Example 4
Project: rapidminer   File: ButtonUI.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	if (RapidLookTools.isToolbarButton(b)) {
		RapidLookTools.drawToolbarButton(g, b);
		super.paint(g, c);
		return;
	}

	int w = c.getWidth();
	int h = c.getHeight();
	if (w <= 0 || h <= 0) {
		return;
	}

	if (b.isContentAreaFilled()) {
		RapidLookTools.drawButton(b, g, RapidLookTools.createShapeForButton(b));
	}
	if (b.isBorderPainted()) {
		RapidLookTools.drawButtonBorder(b, g, RapidLookTools.createBorderShapeForButton(b));
	}
	super.paint(g, c);
}
 
Example 5
Project: rapidminer   File: ComboBoxUI.java   View Source Code Vote up 6 votes
/**
 * Draws the border of the combobox.
 */
private void paintBorder(Graphics g, JComponent c) {
	int w = c.getWidth();
	int h = c.getHeight();
	if (w <= 0 || h <= 0) {
		return;
	}

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	boolean hasFocus = comboBox.isEditable() ? c.isFocusOwner()
			|| ((JComboBox) c).getEditor().getEditorComponent().isFocusOwner() : c.isFocusOwner();
			if (c.isEnabled()) {
				if (hasFocus) {
					g2.setColor(Colors.COMBOBOX_BORDER_FOCUS);
				} else {
					g2.setColor(Colors.COMBOBOX_BORDER);
				}
			} else {
				g2.setColor(Colors.COMBOBOX_BORDER_DISABLED);
			}

			g2.drawRoundRect(0, 0, w - 1, h - 1, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
}
 
Example 6
Project: incubator-netbeans   File: ComponentProvider.java   View Source Code Vote up 5 votes
public PrintPage[][] getPages(int pageWidth, int pageHeight, double pageZoom) {
    List<ComponentPage> pages = new ArrayList<ComponentPage>();
    JComponent component = getComponent();

    if (component == null) {
        return new PrintPage[0][0];
    }
    int componentWidth = component.getWidth();
    int componentHeight = component.getHeight();

    double zoom = getZoom(pageZoom, pageWidth, pageHeight, componentWidth, componentHeight);

    componentWidth = (int) Math.floor(componentWidth * zoom);
    componentHeight = (int) Math.floor(componentHeight * zoom);

    int row = 0;
    int column = 0;

    for (int h = 0; h < componentHeight; h += pageHeight) {
        row++;
        column = 0;

        for (int w = 0; w < componentWidth; w += pageWidth) {
            column++;
            Rectangle piece = new Rectangle((column - 1) * pageWidth, (row - 1) * pageHeight, pageWidth, pageHeight);
            pages.add(new ComponentPage(component, piece, zoom, row - 1, column - 1));
        }
    }
    PrintPage[][] printPages = new PrintPage[row][column];

    for (ComponentPage page : pages) {
        printPages[page.getRow()][page.getColumn()] = page;
    }
    return printPages;
}
 
Example 7
Project: incubator-netbeans   File: ComponentPanel.java   View Source Code Vote up 5 votes
private int getHeight(JComponent component) {
    Dimension size = getSize(component);

    if (size == null) {
        return component.getHeight();
    }
    return size.height;
}
 
Example 8
Project: FreeCol   File: ImageLibrary.java   View Source Code Vote up 5 votes
/**
 * Draw a (usually small) background image into a (usually larger)
 * space specified by a component, tiling the image to fill up the
 * space.  If the image is not available, just fill with the background
 * colour.
 *
 * @param resource The name of the {@code ImageResource} to tile with.
 * @param g The {@code Graphics} to draw to.
 * @param c The {@code JComponent} that defines the space.
 * @param insets Optional {@code Insets} to apply.
 */
public static void drawTiledImage(String resource, Graphics g,
                                  JComponent c, Insets insets) {
    int width = c.getWidth();
    int height = c.getHeight();
    int xmin, ymin;
    if (insets == null) {
        xmin = 0;
        ymin = 0;
    } else {
        xmin = insets.left;
        ymin = insets.top;
        width -= insets.left + insets.right;
        height -= insets.top + insets.bottom;
    }

    if (ResourceManager.hasImageResource(resource)) {
        BufferedImage image = ResourceManager.getImage(resource);
        // FIXME: Test and profile if calling fillTexture is better.
        int dx = image.getWidth();
        int dy = image.getHeight();
        int xmax = xmin + width;
        int ymax = ymin + height;
        for (int x = xmin; x < xmax; x += dx) {
            for (int y = ymin; y < ymax; y += dy) {
                g.drawImage(image, x, y, null);
            }
        }
    } else {
        g.setColor(c.getBackground());
        g.fillRect(xmin, ymin, width, height);
    }
}
 
Example 9
Project: incubator-netbeans   File: AbstractViewTabDisplayerUI.java   View Source Code Vote up 5 votes
@Override
    public Polygon getExactTabIndication(int index) {
        // TBD - the same code is copied in ScrollableTabsUI, should be shared
        // if will not differ
//        GeneralPath indication = new GeneralPath();
        JComponent control = getDisplayer();
        int height = control.getHeight();

        TabLayoutModel tlm = getLayoutModel();

        int tabXStart = tlm.getX(index);

        int tabXEnd = tabXStart + tlm.getW(index);

        int[] xpoints = new int[4];
        int[] ypoints = new int[4];
        xpoints[0] = tabXStart;
        ypoints[0] = 0;
        xpoints[1] = tabXEnd;
        ypoints[1] = 0;
        xpoints[2] = tabXEnd;
        ypoints[2] = height - 1;
        xpoints[3] = tabXStart;
        ypoints[3] = height - 1;

        return new EqualPolygon(xpoints, ypoints);
    }
 
Example 10
Project: incubator-netbeans   File: AbstractViewTabDisplayerUI.java   View Source Code Vote up 5 votes
@Override
public Polygon getInsertTabIndication(int index) {
    EqualPolygon indication = new EqualPolygon();
    JComponent control = getDisplayer();
    int height = control.getHeight();
    int width = control.getWidth();
    TabLayoutModel tlm = getLayoutModel();

    int tabXStart;
    int tabXEnd;
    if (index == 0) {
        tabXStart = 0;
        tabXEnd = tlm.getW(0) / 2;
    } else if (index >= getDataModel().size()) {
        tabXStart = tlm.getX(index - 1) + tlm.getW(index - 1) / 2;
        tabXEnd = tabXStart + tlm.getW(index - 1);
        if (tabXEnd > width) {
            tabXEnd = width;
        }
    } else {
        tabXStart = tlm.getX(index - 1) + tlm.getW(index - 1) / 2;
        tabXEnd = tlm.getX(index) + tlm.getW(index) / 2;
    }

    indication.moveTo(tabXStart, 0);
    indication.lineTo(tabXEnd, 0);
    indication.lineTo(tabXEnd, height - 1);
    indication.lineTo(tabXStart, height - 1);
    return indication;
}
 
Example 11
Project: openjdk-jdk10   File: SynthToggleButtonUI.java   View Source Code Vote up 5 votes
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) {
    if (((AbstractButton) c).isContentAreaFilled()) {
        int x = 0, y = 0, w = c.getWidth(), h = c.getHeight();
        SynthPainter painter = context.getPainter();
        painter.paintToggleButtonBackground(context, g, x, y, w, h);
    }
}
 
Example 12
Project: incubator-netbeans   File: ButtonPopupSwitcher.java   View Source Code Vote up 5 votes
/** Creates a new instance of TabListPanel */
private ButtonPopupSwitcher(JComponent owner, SwitcherTableItem items[], int x, int y) {
    int ownerWidth = owner.getWidth();
    int ownerHeight = owner.getHeight();
    int cornerX, cornerY;
    int xOrient, yOrient;
    Rectangle screenRect = Utilities.getUsableScreenBounds();

    // get rid of the effect when popup seems to be higher that screen height
    int gap = (y == 0 ? 10 : 5);
    int height = 0;
    int width = 0;

    int leftD = x - screenRect.x;
    int rightD = screenRect.x + screenRect.width - x;
    if (leftD < rightD / 2) {
        xOrient = 1;
        width = rightD;
        cornerX = x + 1;
    } else {
        xOrient = -1;
        width = leftD + ownerWidth;
        cornerX = x + ownerWidth;
    }
    int topD = y - screenRect.y;
    int bottomD = screenRect.y + screenRect.height - y;
    if (bottomD < topD / 4) {
        yOrient = -1;
        height = topD - gap;
        cornerY = y;
    } else {
        yOrient = 1;
        cornerY = y + ownerHeight;
        height = screenRect.height - cornerY - gap;
    }

    this.pTable = new SwitcherTable(items, height, width);
    this.x = cornerX - (xOrient == -1 ? (int) pTable.getPreferredSize().getWidth() : 0);
    this.y = cornerY - (yOrient == -1 ? (int) pTable.getPreferredSize().getHeight() : 0);
}
 
Example 13
Project: jdk8u-jdk   File: SynthToggleButtonUI.java   View Source Code Vote up 5 votes
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) {
    if (((AbstractButton) c).isContentAreaFilled()) {
        int x = 0, y = 0, w = c.getWidth(), h = c.getHeight();
        SynthPainter painter = context.getPainter();
        painter.paintToggleButtonBackground(context, g, x, y, w, h);
    }
}
 
Example 14
Project: freecol   File: ImageLibrary.java   View Source Code Vote up 5 votes
/**
 * Draw a (usually small) background image into a (usually larger)
 * space specified by a component, tiling the image to fill up the
 * space.  If the image is not available, just fill with the background
 * colour.
 *
 * @param resource The name of the {@code ImageResource} to tile with.
 * @param g The {@code Graphics} to draw to.
 * @param c The {@code JComponent} that defines the space.
 * @param insets Optional {@code Insets} to apply.
 */
public static void drawTiledImage(String resource, Graphics g,
                                  JComponent c, Insets insets) {
    int width = c.getWidth();
    int height = c.getHeight();
    int xmin, ymin;
    if (insets == null) {
        xmin = 0;
        ymin = 0;
    } else {
        xmin = insets.left;
        ymin = insets.top;
        width -= insets.left + insets.right;
        height -= insets.top + insets.bottom;
    }

    if (ResourceManager.hasImageResource(resource)) {
        BufferedImage image = ResourceManager.getImage(resource);
        // FIXME: Test and profile if calling fillTexture is better.
        int dx = image.getWidth();
        int dy = image.getHeight();
        int xmax = xmin + width;
        int ymax = ymin + height;
        for (int x = xmin; x < xmax; x += dx) {
            for (int y = ymin; y < ymax; y += dy) {
                g.drawImage(image, x, y, null);
            }
        }
    } else {
        g.setColor(c.getBackground());
        g.fillRect(xmin, ymin, width, height);
    }
}
 
Example 15
Project: Logisim   File: JTreeUtil.java   View Source Code Vote up 4 votes
@Override
public final void dragGestureRecognized(DragGestureEvent dge) {
	TreePath path = tree.getSelectionPath();
	if (path != null) {
		draggedNode = path.getLastPathComponent();
		if (drawImage) {
			Rectangle pathBounds = tree.getPathBounds(path); // getpathbounds
																// of
																// selectionpath
			JComponent lbl = (JComponent) tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode,
					false, tree.isExpanded(path), tree.getModel().isLeaf(path.getLastPathComponent()), 0,
					false);// returning the label
			lbl.setBounds(pathBounds);// setting bounds to lbl
			image = new BufferedImage(lbl.getWidth(), lbl.getHeight(),
					java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);// buffered
																	// image
																	// reference
																	// passing
																	// the
																	// label's
																	// ht
																	// and
																	// width
			Graphics2D graphics = image.createGraphics();// creating
															// the
															// graphics
															// for
															// buffered
															// image
			graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); // Sets
																								// the
																								// Composite
																								// for
																								// the
																								// Graphics2D
																								// context
			lbl.setOpaque(false);
			lbl.paint(graphics); // painting the graphics to label
			graphics.dispose();
		}
		dragSource.startDrag(dge, DragSource.DefaultMoveNoDrop, image, new Point(0, 0),
				new TransferableNode(draggedNode), this);
	}
}
 
Example 16
Project: incubator-netbeans   File: DropTargetLayer.java   View Source Code Vote up 4 votes
public static boolean isBelowItem(Point pt, JComponent tcomp) {
    return pt.y > tcomp.getHeight()/2;
}
 
Example 17
Project: faitic-checker   File: CustomScrollBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {

	boolean isVertical=c.getWidth()<c.getHeight();
	
	int barwidth=isVertical ? thumbBounds.width/2 : thumbBounds.height/2;
	
	Graphics2D g2=(Graphics2D) g;
	
 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
	g2.setColor(fore);
	
	if(isVertical)
		g2.fillRoundRect(thumbBounds.x+barwidth/2, thumbBounds.y, barwidth, thumbBounds.height, barwidth,barwidth);
	else
		g2.fillRoundRect(thumbBounds.x, thumbBounds.y+barwidth/2, thumbBounds.width, barwidth, barwidth,barwidth);
	
}
 
Example 18
Project: rapidminer   File: ProgressBarUI.java   View Source Code Vote up 4 votes
@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);
}
 
Example 19
Project: rapidminer   File: ProgressBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintIndeterminate(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;
	}

	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);

	// make sure we don't draw over the boundaries
	RoundRectangle2D clipRect = new RoundRectangle2D.Double(x + 3, y + 3, w - 5, h - 5,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
	g2.setClip(clipRect);

	for (double xCoord = x + -4 * ANIMATION_BAR_LENGTH + System.currentTimeMillis() * ANIMATION_SPEED
			% (2 * ANIMATION_BAR_LENGTH); xCoord < x + w + 2 * ANIMATION_BAR_LENGTH;) {
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_1);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_2);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
	}
	g2.setClip(null);

	drawString(g2, w, h, compressed);
}
 
Example 20
Project: faitic-checker   File: CustomScrollBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
	
	boolean isVertical=c.getWidth()<c.getHeight();
	
	g.setColor(back);
	g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);

	int barwidth=isVertical ? trackBounds.width/2 : trackBounds.height/2;
	
	Graphics2D g2=(Graphics2D) g;
	
 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
	g2.setColor(forenobar);
	
	if(isVertical)
		g2.fillRoundRect(trackBounds.x+barwidth/2, trackBounds.y, barwidth, trackBounds.height, barwidth,barwidth);
	else
		g2.fillRoundRect(trackBounds.x, trackBounds.y+barwidth/2, trackBounds.width, barwidth, barwidth,barwidth);

}