Java Code Examples for javax.swing.JLabel#getBaseline()
The following examples show how to use
javax.swing.JLabel#getBaseline() .
These examples are extracted from open source projects.
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 Project: jdk1.8-source-analysis File: TitledBorder.java License: Apache License 2.0 | 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
Source Project: dragonwell8_jdk File: TitledBorder.java License: GNU General Public License v2.0 | 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
Source Project: TencentKona-8 File: TitledBorder.java License: GNU General Public License v2.0 | 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 4
Source Project: jdk8u60 File: TitledBorder.java License: GNU General Public License v2.0 | 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 5
Source Project: JDKSourceCode1.8 File: TitledBorder.java License: MIT License | 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 6
Source Project: openjdk-jdk8u File: TitledBorder.java License: GNU General Public License v2.0 | 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 7
Source Project: openjdk-jdk8u-backup File: TitledBorder.java License: GNU General Public License v2.0 | 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 8
Source Project: Bytecoder File: TitledBorder.java License: Apache License 2.0 | 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 9
Source Project: openjdk-jdk9 File: TitledBorder.java License: GNU General Public License v2.0 | 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 10
Source Project: jdk8u-jdk File: TitledBorder.java License: GNU General Public License v2.0 | 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 11
Source Project: Java8CN File: TitledBorder.java License: Apache License 2.0 | 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 12
Source Project: hottub File: TitledBorder.java License: GNU General Public License v2.0 | 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 13
Source Project: openjdk-8-source File: TitledBorder.java License: GNU General Public License v2.0 | 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 14
Source Project: openjdk-8 File: TitledBorder.java License: GNU General Public License v2.0 | 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 15
Source Project: jdk8u_jdk File: TitledBorder.java License: GNU General Public License v2.0 | 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 16
Source Project: jdk8u-jdk File: TitledBorder.java License: GNU General Public License v2.0 | 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 17
Source Project: jdk8u-dev-jdk File: TitledBorder.java License: GNU General Public License v2.0 | 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; }