javax.swing.JComponent#getHeight ( )源码实例Demo

下面列出了javax.swing.JComponent#getHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pumpernickel   文件: BoxTabbedPaneUI.java
protected GradientPaint createContentGradient(JComponent c,
		boolean isSelected) {
	JTabbedPane tabs = getTabbedPaneParent(c);
	int placement = tabs == null ? SwingConstants.TOP : tabs
			.getTabPlacement();
	Color outer = isSelected ? contentOuterSelected
			: contentOuterNormal;
	Color inner = isSelected ? contentInnerSelected
			: contentInnerNormal;
	if (placement == SwingConstants.LEFT) {
		return (new GradientPaint(0, 0, outer, c.getWidth(), 0, inner));
	} else if (placement == SwingConstants.RIGHT) {
		return (new GradientPaint(0, 0, inner, c.getWidth(), 0, outer));
	} else if (placement == SwingConstants.BOTTOM) {
		return (new GradientPaint(0, 0, inner, 0, c.getHeight(), outer));
	} else {
		return (new GradientPaint(0, 0, outer, 0, c.getHeight(), inner));
	}
}
 
源代码2 项目: netbeans   文件: TabListPopupAction.java
@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();
        }
    }
}
 
源代码3 项目: TrakEM2   文件: AbstractTreeTransferHandler.java
public final void dragGestureRecognized(DragGestureEvent dge) {
        TreePath path = tree.getSelectionPath(); 
        if (path != null) { 
                draggedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
                draggedNodeParent = (DefaultMutableTreeNode)draggedNode.getParent();
                if (drawImage) {
                        Rectangle pathBounds = tree.getPathBounds(path); //getpathbounds of selectionpath
                        JComponent lbl = (JComponent)tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode, false , tree.isExpanded(path),((DefaultTreeModel)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);                       
        }        
}
 
源代码4 项目: mars-sim   文件: MainDesktopManager.java
@Override
public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
	boolean hitBoundary = (f.getWidth() != newWidth || f.getHeight() != newHeight);

	if (!inBounds((JInternalFrame) f, newX, newY, newWidth, newHeight)) {
		Container parent = f.getParent();
		Dimension parentSize = parent.getSize();

		// Limit the unit window or tool windows to stay inside and never go outside of
		// the desktop
		// or always show up fully (never show up less than the full window)
		int boundedX = (int) Math.min(Math.max(0, newX), parentSize.getWidth() - newWidth);
		int boundedY = (int) Math.min(Math.max(0, newY), parentSize.getHeight() - 40);// newHeight);
		if (f != null)
			f.setBounds(boundedX, boundedY, newWidth, newHeight);
	} else {
		if (f != null)
			f.setBounds(newX, newY, newWidth, newHeight);
	}

	if (hitBoundary) {
		if (f != null)
			f.validate();
	}

}
 
源代码5 项目: seaglass   文件: SeaGlassIcon.java
/**
 * Returns the icon's height. This is a cover method for <code>
 * getIconHeight(null)</code>.
 *
 * @param  context the SynthContext describing the component/region, the
 *                 style, and the state.
 *
 * @return an int specifying the fixed height of the icon.
 */
@Override
public int getIconHeight(SynthContext context) {
    if (context == null) {
        return height;
    }

    JComponent c = context.getComponent();

    if (c instanceof JToolBar) {
        JToolBar toolbar = (JToolBar) c;

        if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {

            // we only do the -1 hack for UIResource borders, assuming
            // that the border is probably going to be our border
            if (toolbar.getBorder() instanceof UIResource) {
                return c.getHeight() - 1;
            } else {
                return c.getHeight();
            }
        } else {
            return scale(context, width);
        }
    } else {
        return scale(context, height);
    }
}
 
源代码6 项目: netbeans   文件: ComponentProvider.java
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;
}
 
源代码7 项目: Bytecoder   文件: SynthToggleButtonUI.java
@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);
    }
}
 
源代码8 项目: jdk8u-jdk   文件: SynthToggleButtonUI.java
@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);
    }
}
 
源代码9 项目: uima-uimaj   文件: CloseTypeSystemHandler.java
@Override
public void windowClosing(WindowEvent event) {
  JComponent tsContentPane = (JComponent) ((JFrame) event.getComponent()).getContentPane();
  final int x = tsContentPane.getWidth();
  final int y = tsContentPane.getHeight();
  this.main.getPreferences().setProperty(MainFrame.tsWindowSizePref + MainFrame.widthSuffix,
      Integer.toString(x));
  this.main.getPreferences().setProperty(MainFrame.tsWindowSizePref + MainFrame.heightSuffix,
      Integer.toString(y));
}
 
源代码10 项目: binnavi   文件: AbstractTreeTransferHandler.java
@Override
public final void dragGestureRecognized(final DragGestureEvent dge) {
  // final TreePath path = tree.getSelectionPath();
  final TreePath path = tree.getPathForLocation(dge.getDragOrigin().x, dge.getDragOrigin().y);

  if (path != null) {
    draggedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    draggedNodeParent = (DefaultMutableTreeNode) draggedNode.getParent();
    if (drawImage) {
      final Rectangle pathBounds = tree.getPathBounds(path); // getpathbounds of selectionpath
      final JComponent lbl =
          (JComponent) tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode,
              false, tree.isExpanded(path),
              ((DefaultTreeModel) 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
      final 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);
  }
}
 
源代码11 项目: mars-sim   文件: WaitLayerUI.java
@Override
public void paint(Graphics g, JComponent c) {
	int w = c.getWidth();
	int h = c.getHeight();

	// Paint the view.
	super.paint(g, c);

	if (!mIsRunning) {
		return;
	}

	Graphics2D g2 = (Graphics2D) g.create();

	float fade = (float) mFadeCount / (float) mFadeLimit;
	// Gray it out.
	Composite urComposite = g2.getComposite();
	g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade));
	g2.fillRect(0, 0, w, h);
	g2.setComposite(urComposite);

	// Paint the wait indicator.
	int s = Math.min(w, h) / 5;
	int cx = w / 2;
	int cy = h / 2;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
	g2.setPaint(Color.white);
	g2.rotate(Math.PI * mAngle / 180, cx, cy);
	for (int i = 0; i < 12; i++) {
		float scale = (11.0f - (float) i) / 11.0f;
		g2.drawLine(cx + s, cy, cx + s * 2, cy);
		g2.rotate(-Math.PI / 6, cx, cy);
		g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade));
	}

	g2.dispose();
}
 
源代码12 项目: settlers-remake   文件: BackgroundPanelUi.java
/**
 * Recreate the cached background image, if needed
 *
 * @param component
 *            The component
 */
private void recreateBackgroundImage(JComponent component) {
	final int width = component.getWidth();
	final int height = component.getHeight();

	cachedBackground = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	cachedForeground = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

	Graphics2D graphics = cachedBackground.createGraphics();

	// scale the background color image
	graphics.drawImage(backgroundTexture, 0, 0, width, height, component);

	BorderDrawer border = new BorderDrawer(graphics, 3, 0, 0, width, height);
	BufferedImage scaledTexture = DrawHelper.toBufferedImage(borderTexture.getScaledInstance(width, height, BufferedImage.SCALE_FAST));
	TexturePaint tp = new TexturePaint(scaledTexture, new Rectangle2D.Float(0, 0, width, height));
	border.setPaint(tp);
	border.drawRect();

	if (component instanceof SplitedBackgroundPanel) {
		border.drawVertical(((SplitedBackgroundPanel) component).getSplitPosition(), true);
	}

	graphics.dispose();

	graphics = cachedForeground.createGraphics();

	float factor = height / 2160f * 0.9f;
	factor = Math.min(factor, 0.535f);
	int w = (int) (leavesRight.getWidth() * factor);
	int h = (int) (leavesRight.getHeight() * factor);
	graphics.drawImage(leavesRight, width - w, 0, w, h, component);

	w = (int) (leavesLeft.getWidth() * factor);
	h = (int) (leavesLeft.getHeight() * factor);
	graphics.drawImage(leavesLeft, 0, 0, w, h, component);

	graphics.dispose();
}
 
源代码13 项目: openjdk-jdk8u   文件: SynthToggleButtonUI.java
@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);
    }
}
 
源代码14 项目: jdk8u-jdk   文件: SynthToggleButtonUI.java
@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);
    }
}
 
源代码15 项目: pumpernickel   文件: CircularProgressBarUI.java
@Override
public void paint(Graphics g0, JComponent c) {
	Graphics2D g = (Graphics2D) g0;
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
			RenderingHints.VALUE_STROKE_PURE);

	Insets i = progressBar.getInsets();

	int x = 0;
	int y = 0;
	int width = c.getWidth();
	int height = c.getHeight();
	x += i.left;
	y += i.top;
	width -= i.left + i.right;
	height -= i.top + i.bottom;

	int diameter = Math.min(width, height);
	int radius = diameter / 2;
	int centerX = x + width / 2;
	int centerY = y + height / 2;

	float strokeWidth = getStrokeWidth(diameter);

	if (progressBar.isIndeterminate()) {
		paintIndeterminate(g, radius, strokeWidth, centerX, centerY);
	} else {
		paintDeterminate(g, radius, strokeWidth, centerX, centerY);
	}
}
 
源代码16 项目: netbeans   文件: AbstractViewTabDisplayerUI.java
@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;
}
 
源代码17 项目: FlatLaf   文件: FlatDatePickerUI.java
@Override
public void update( Graphics g, JComponent c ) {
	// fill background if opaque to avoid garbage if user sets opaque to true
	if( c.isOpaque() )
		FlatUIUtils.paintParentBackground( g, c );

	Graphics2D g2 = (Graphics2D) g;
	FlatUIUtils.setRenderingHints( g2 );

	int width = c.getWidth();
	int height = c.getHeight();
	float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
	float arc = FlatUIUtils.getBorderArc( c );
	int arrowX = popupButton.getX();
	int arrowWidth = popupButton.getWidth();
	boolean enabled = c.isEnabled();
	boolean isLeftToRight = c.getComponentOrientation().isLeftToRight();

	// paint background
	g2.setColor( enabled ? c.getBackground() : disabledBackground );
	FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );

	// paint arrow button background
	if( enabled ) {
		g2.setColor( buttonBackground );
		Shape oldClip = g2.getClip();
		if( isLeftToRight )
			g2.clipRect( arrowX, 0, width - arrowX, height );
		else
			g2.clipRect( 0, 0, arrowX + arrowWidth, height );
		FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
		g2.setClip( oldClip );
	}

	// paint vertical line between value and arrow button
	g2.setColor( enabled ? borderColor : disabledBorderColor );
	float lw = scale( 1f );
	float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
	g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2) ) );

	paint( g, c );
}
 
源代码18 项目: seaglass   文件: SeaGlassGraphicsUtils.java
/**
 * Paints an icon and text. This will render the text as html, if necessary,
 * and offset the location by the insets of the component.
 *
 * @param ss
 *            SynthContext
 * @param g
 *            Graphics to render string and icon into
 * @param text
 *            Text to layout
 * @param icon
 *            Icon to layout
 * @param hAlign
 *            horizontal alignment
 * @param vAlign
 *            vertical alignment
 * @param hTextPosition
 *            horizontal text position
 * @param vTextPosition
 *            vertical text position
 * @param iconTextGap
 *            gap between icon and text
 * @param mnemonicIndex
 *            Index into text to render the mnemonic at, -1 indicates no
 *            mnemonic.
 * @param textOffset
 *            Amount to offset the text when painting
 */
public void paintText(SynthContext ss, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition,
    int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset) {
    if ((icon == null) && (text == null)) {
        return;
    }

    Graphics2D g2d = (Graphics2D) g.create();

    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    JComponent c = ss.getComponent();
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g2d);
    Insets insets = SeaGlassLookAndFeel.getPaintingInsets(ss, paintInsets);

    paintViewR.x = insets.left;
    paintViewR.y = insets.top;
    paintViewR.width = c.getWidth() - (insets.left + insets.right);
    paintViewR.height = c.getHeight() - (insets.top + insets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    String clippedText = layoutText(ss, fm, text, icon, hAlign, vAlign, hTextPosition, vTextPosition, paintViewR, paintIconR,
        paintTextR, iconTextGap);

    if (icon != null) {
        Color color = g2d.getColor();

        paintIconR.x += textOffset;
        paintIconR.y += textOffset;
        SeaGlassIcon.paintIcon(icon, ss, g2d, paintIconR.x, paintIconR.y, paintIconR.width, paintIconR.height);
        g2d.setColor(color);
    }

    if (text != null) {
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);

        if (v != null) {
            v.paint(g2d, paintTextR);
        } else {
            paintTextR.x += textOffset;
            paintTextR.y += textOffset;

            paintText(ss, g2d, clippedText, paintTextR, mnemonicIndex);
        }
    }
}
 
源代码19 项目: FlatLaf   文件: FlatUIUtils.java
public static boolean hasRoundBorder( JComponent c ) {
	return getBorderArc( c ) >= c.getHeight();
}
 
源代码20 项目: rapidminer-studio   文件: ProgressBarUI.java
@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);
}