Java Code Examples for javax.swing.JLabel.getBaseline()
The following are Jave code examples for showing how to use
getBaseline() 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.
+ Save this method
Example 1
Project: OpenJSharp File: TitledBorder.java View Source Code | 4 votes |
/** * Returns the baseline. * * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public int getBaseline(Component c, int width, int height) { if (c == null) { throw new NullPointerException("Must supply non-null component"); } if (width < 0) { throw new IllegalArgumentException("Width must be >= 0"); } if (height < 0) { throw new IllegalArgumentException("Height must be >= 0"); } Border border = getBorder(); String title = getTitle(); if ((title != null) && !title.isEmpty()) { int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; JLabel label = getLabel(c); Dimension size = label.getPreferredSize(); Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0)); int baseline = label.getBaseline(size.width, size.height); switch (getPosition()) { case ABOVE_TOP: return baseline; case TOP: insets.top = edge + (insets.top - size.height) / 2; return (insets.top < edge) ? baseline : baseline + insets.top; case BELOW_TOP: return baseline + insets.top + edge; case ABOVE_BOTTOM: return baseline + height - size.height - insets.bottom - edge; case BOTTOM: insets.bottom = edge + (insets.bottom - size.height) / 2; return (insets.bottom < edge) ? baseline + height - size.height : baseline + height - size.height + insets.bottom; case BELOW_BOTTOM: return baseline + height - size.height; } } return -1; }
Example 2
Project: jdk8u-jdk File: TitledBorder.java View Source Code | 4 votes |
/** * Returns the baseline. * * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public int getBaseline(Component c, int width, int height) { if (c == null) { throw new NullPointerException("Must supply non-null component"); } if (width < 0) { throw new IllegalArgumentException("Width must be >= 0"); } if (height < 0) { throw new IllegalArgumentException("Height must be >= 0"); } Border border = getBorder(); String title = getTitle(); if ((title != null) && !title.isEmpty()) { int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; JLabel label = getLabel(c); Dimension size = label.getPreferredSize(); Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0)); int baseline = label.getBaseline(size.width, size.height); switch (getPosition()) { case ABOVE_TOP: return baseline; case TOP: insets.top = edge + (insets.top - size.height) / 2; return (insets.top < edge) ? baseline : baseline + insets.top; case BELOW_TOP: return baseline + insets.top + edge; case ABOVE_BOTTOM: return baseline + height - size.height - insets.bottom - edge; case BOTTOM: insets.bottom = edge + (insets.bottom - size.height) / 2; return (insets.bottom < edge) ? baseline + height - size.height : baseline + height - size.height + insets.bottom; case BELOW_BOTTOM: return baseline + height - size.height; } } return -1; }
Example 3
Project: openjdk-jdk10 File: TitledBorder.java View Source Code | 4 votes |
/** * Returns the baseline. * * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public int getBaseline(Component c, int width, int height) { if (c == null) { throw new NullPointerException("Must supply non-null component"); } if (width < 0) { throw new IllegalArgumentException("Width must be >= 0"); } if (height < 0) { throw new IllegalArgumentException("Height must be >= 0"); } Border border = getBorder(); String title = getTitle(); if ((title != null) && !title.isEmpty()) { int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; JLabel label = getLabel(c); Dimension size = label.getPreferredSize(); Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0)); int baseline = label.getBaseline(size.width, size.height); switch (getPosition()) { case ABOVE_TOP: return baseline; case TOP: insets.top = edge + (insets.top - size.height) / 2; return (insets.top < edge) ? baseline : baseline + insets.top; case BELOW_TOP: return baseline + insets.top + edge; case ABOVE_BOTTOM: return baseline + height - size.height - insets.bottom - edge; case BOTTOM: insets.bottom = edge + (insets.bottom - size.height) / 2; return (insets.bottom < edge) ? baseline + height - size.height : baseline + height - size.height + insets.bottom; case BELOW_BOTTOM: return baseline + height - size.height; } } return -1; }