当前位置: 首页>>代码示例>>Java>>正文


Java SwingUtilities.layoutCompoundLabel方法代码示例

本文整理汇总了Java中javax.swing.SwingUtilities.layoutCompoundLabel方法的典型用法代码示例。如果您正苦于以下问题:Java SwingUtilities.layoutCompoundLabel方法的具体用法?Java SwingUtilities.layoutCompoundLabel怎么用?Java SwingUtilities.layoutCompoundLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.SwingUtilities的用法示例。


在下文中一共展示了SwingUtilities.layoutCompoundLabel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: layoutLabel

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
/**
 * Layouts the label
 *
 * @param tabPlacement the placement of the tabs
 * @param metrics      the font metrics
 * @param tabIndex     the index of the tab
 * @param title        the title of the tab
 * @param icon         the icon of the tab
 * @param tabRect      the tab boundaries
 * @param iconRect     the icon boundaries
 * @param textRect     the text boundaries
 * @param isSelected   true whether the tab is selected, false otherwise
 */
protected void layoutLabel(int tabPlacement, FontMetrics metrics,
                           int tabIndex, String title, Icon icon, Rectangle tabRect,
                           Rectangle iconRect, Rectangle textRect, boolean isSelected) {

    textRect.x = textRect.y = iconRect.x = iconRect.y = 0;

    javax.swing.text.View v = getTextViewForTab(tabIndex);
    if (v != null) {
        tabPane.putClientProperty("html", v);
    }

    SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon,
            SwingUtilities.CENTER, SwingUtilities.CENTER,
            SwingUtilities.CENTER,
            // SwingUtilities.TRAILING,
            horizontalTextPosition, tabRect, iconRect, textRect,
            textIconGap + 2);

    tabPane.putClientProperty("html", null);

    int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
    int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
    iconRect.x += xNudge;
    iconRect.y += yNudge;
    textRect.x += xNudge;
    textRect.y += yNudge;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:41,代码来源:CloseableTabbedPane.java

示例2: originalPaint

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
public void originalPaint(Graphics graphics) {
    Graphics2D g2d = (Graphics2D)graphics;
    if (!isEnabled()) {
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.3f));
    }
    
    graphics.setColor(color_text);
    graphics.drawImage(image, 0, 0, null);
    
    if (text == null) {
        // no text to draw
        return;
    }
    
    if (fm == null) {
        // XXX(-ttran) this happened on Japanese Windows NT, don't
        // fully understand why
        return;
    }
    
    SwingUtilities.layoutCompoundLabel(fm, text, null,
            SwingConstants.BOTTOM, SwingConstants.LEFT, SwingConstants.BOTTOM, SwingConstants.LEFT,
            this.view, new Rectangle(), rect, 0);
    // turn anti-aliasing on for the splash text
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.drawString(text, rect.x, rect.y + fm.getAscent());
    // Draw progress bar if applicable
    
    if (draw_bar && Boolean.getBoolean("netbeans.splash.nobar") == false && maxSteps > 0/* && barLength > 0*/) {
        graphics.setColor(color_bar);
        graphics.fillRect(bar.x, bar.y, barStart + barLength, bar.height);
        graphics.setColor(color_corner);
        graphics.drawLine(bar.x, bar.y, bar.x, bar.y + bar.height);
        graphics.drawLine(bar.x + barStart + barLength, bar.y, bar.x + barStart + barLength, bar.y + bar.height);
        graphics.setColor(color_edge);
        graphics.drawLine(bar.x, bar.y + bar.height / 2, bar.x, bar.y + bar.height / 2);
        graphics.drawLine(bar.x + barStart + barLength, bar.y + bar.height / 2, bar.x + barStart + barLength, bar.y + bar.height / 2);
        barStart += barLength;
        barLength = 0;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:SplashComponentPreview.java

示例3: paint

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;

	Dimension size = b.getSize();
	FontMetrics fm = g.getFontMetrics();

	Insets i = c.getInsets();

	Rectangle viewRect = new Rectangle(size);

	viewRect.x += i.left;
	viewRect.y += i.top;
	viewRect.width -= i.right + viewRect.x;
	viewRect.height -= i.bottom + viewRect.y;

	Rectangle iconRect = new Rectangle();
	Rectangle textRect = new Rectangle();

	Font f = c.getFont();
	g.setFont(f);

	String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(),
			b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect,
			textRect, b.getText() == null ? 0 : b.getIconTextGap());

	g.setColor(b.getBackground());

	if (b.isContentAreaFilled()) {
		if (RapidLookTools.isToolbarButton(b)) {
			RapidLookTools.drawToolbarButton(g, b);
		} else {
			RapidLookTools.drawButton(b, g, RapidLookTools.createShapeForButton(b));
		}
	}

	if (b.getIcon() != null) {
		paintIcon(g, b, iconRect);
	}

	if (text != null && !text.equals("")) {
		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g, textRect);
		} else {
			paintText(g, b, textRect, text);
		}
	}

	if (b.isFocusPainted() && b.hasFocus()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
	}

	if (!RapidLookTools.isToolbarButton(b)) {
		if (b.isBorderPainted()) {
			RapidLookTools.drawButtonBorder(b, g, RapidLookTools.createBorderShapeForButton(b));
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:60,代码来源:ToggleButtonUI.java

示例4: paintPeer

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
/**
 * This method is called from Toolkit Thread and so it should not call any
 * client code.
 */
@Override
void paintPeer(final Graphics g) {
    if (!disposed) {
        Dimension size = getPeerSize();
        g.setColor( getPeerBackground() );   /* erase the existing button remains */
        g.fillRect(0,0, size.width , size.height);
        paintBorder(g,borderInsets.left,
                    borderInsets.top,
                    size.width-(borderInsets.left+borderInsets.right),
                    size.height-(borderInsets.top+borderInsets.bottom));

        FontMetrics fm = g.getFontMetrics();

        Rectangle textRect,iconRect,viewRect;

        textRect = new Rectangle();
        viewRect = new Rectangle();
        iconRect = new Rectangle();


        viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right);
        viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom);
        viewRect.x = contentAreaInsets.left;
        viewRect.y = contentAreaInsets.top;
        String llabel = (label != null) ? label : "";
        // layout the text and icon
        String text = SwingUtilities.layoutCompoundLabel(
                                                         fm, llabel, null,
                                                         SwingConstants.CENTER, SwingConstants.CENTER,
                                                         SwingConstants.CENTER, SwingConstants.CENTER,
                                                         viewRect, iconRect, textRect, 0);

        Font f = getPeerFont();

        g.setFont(f);

        // perform UI specific press action, e.g. Windows L&F shifts text
        if (pressed && armed) {
            paintButtonPressed(g,target);
        }

        paintText(g, target, textRect, text);

        if (hasFocus()) {
            // paint UI specific focus
            paintFocus(g,focusInsets.left,
                       focusInsets.top,
                       size.width-(focusInsets.left+focusInsets.right)-1,
                       size.height-(focusInsets.top+focusInsets.bottom)-1);
        }
    }
    flush();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:58,代码来源:XButtonPeer.java

示例5: paintComponent

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    // Set the foreground on the fly to ensure the text is painted
    // with the proper color in super.paintComponent
    ButtonModel model = getModel();
    if (model.isArmed()) {
        super.setForeground(activeForeground);
    } else if (visited) {
        super.setForeground(visitedForeground);
    } else {
        super.setForeground(normalForeground);
    }
    super.paintComponent(g);

    if (drawUnderline) {
        Insets insets = getInsets();
        viewRect.x = insets.left;
        viewRect.y = insets.top;
        viewRect.width = getWidth() - insets.left - insets.right;
        viewRect.height = getHeight() - insets.top - insets.bottom;
        int baseline = getBaseline(viewRect.width, viewRect.height);

        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
        textRect.x = textRect.y = textRect.width = textRect.height = 0;
        SwingUtilities.layoutCompoundLabel(g.getFontMetrics(), getText(),
                getIcon(), getVerticalAlignment(), getHorizontalAlignment(),
                getVerticalTextPosition(), getHorizontalTextPosition(),
                viewRect, iconRect, textRect, getIconTextGap());

        // getBaseline not returning correct results, so workaround for now
        if (UIManager.getLookAndFeel().getName().equals("Nimbus")) {
            baseline += 7;
        } else {
            baseline += 3;
        }

        g.setColor(getForeground());
        g.drawLine(textRect.x,
                baseline,
                textRect.x + textRect.width,
                baseline);
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:JHyperlink.java


注:本文中的javax.swing.SwingUtilities.layoutCompoundLabel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。