本文整理匯總了Java中javax.swing.plaf.basic.BasicGraphicsUtils.drawStringUnderlineCharAt方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicGraphicsUtils.drawStringUnderlineCharAt方法的具體用法?Java BasicGraphicsUtils.drawStringUnderlineCharAt怎麽用?Java BasicGraphicsUtils.drawStringUnderlineCharAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.plaf.basic.BasicGraphicsUtils
的用法示例。
在下文中一共展示了BasicGraphicsUtils.drawStringUnderlineCharAt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDrawEmptyString
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
private static void testDrawEmptyString() {
JLabel label = new JLabel();
BufferedImage buffImage = createBufferedImage(50, 50);
Graphics2D g2 = buffImage.createGraphics();
g2.setColor(DRAW_COLOR);
BasicGraphicsUtils.drawString(null, g2, null, 0, 0);
BasicGraphicsUtils.drawString(label, g2, null, 0, 0);
BasicGraphicsUtils.drawString(null, g2, "", 0, 0);
BasicGraphicsUtils.drawString(label, g2, "", 0, 0);
BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, null, 3, 0, 0);
BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, null, 3, 0, 0);
BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, "", 3, 0, 0);
BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, "", 3, 0, 0);
g2.dispose();
checkImageIsEmpty(buffImage);
}
示例2: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title,
Rectangle textRect, boolean isSelected)
{
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if( v != null )
{
// html
v.paint(g, textRect);
}
else
{
// plain text
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if( tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex) )
{
g.setColor(isSelected ? Color.white : Color.black);
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
textRect.y + metrics.getAscent());
}
else
{ // tab disabled
g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
textRect.y + metrics.getAscent());
g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
textRect.y + metrics.getAscent());
}
}
}
示例3: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void paintText(Graphics g, Rectangle textRect, String text) {
FontMetrics fm = g.getFontMetrics();
int mnemonicIndex = -1;
if(isEnabled()) {
/*** paint the text normally */
g.setColor(getPeerForeground());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
}
else {
/*** paint the text disabled ***/
g.setColor(getPeerBackground().brighter());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
textRect.x, textRect.y + fm.getAscent());
g.setColor(getPeerBackground().darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
textRect.x - 1, textRect.y + fm.getAscent() - 1);
}
}
示例4: checkNullArgumentsDrawStringUnderlineCharAt
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
private static void checkNullArgumentsDrawStringUnderlineCharAt(
JComponent comp, Graphics2D g, String text) {
int x = 50;
int y = 50;
BasicGraphicsUtils.drawStringUnderlineCharAt(null, g, text, 1, x, y);
BasicGraphicsUtils.drawStringUnderlineCharAt(comp, g, null, 1, x, y);
try {
BasicGraphicsUtils.drawStringUnderlineCharAt(comp, null, text, 1, x, y);
} catch (NullPointerException e) {
return;
}
throw new RuntimeException("NPE is not thrown");
}
示例5: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
public void paintText(Graphics2D g,ButtonInfo info) {
ButtonModel model = info.button.getModel();
FontMetrics fm = info.button.getFontMetrics(info.button.getFont());
int mnemonicIndex = info.button.getDisplayedMnemonicIndex();
String text = info.button.getText();
int textShiftOffset = 0;
g.setComposite(AlphaComposite.SrcOver);
/* Draw the Text */
if(isEnabled(info.button)) {
/*** paint the text normally */
g.setColor(info.button.getForeground());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
info.textRect.x + textShiftOffset,
info.textRect.y + fm.getAscent() + textShiftOffset);
} else {
/*** paint the text disabled ***/
g.setColor(info.button.getBackground().brighter());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
info.textRect.x, info.textRect.y + fm.getAscent());
g.setColor(info.button.getBackground().darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
info.textRect.x - 1, info.textRect.y + fm.getAscent() - 1);
}
}
示例6: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
@Override
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
MacFontUtils.enableAntialiasing((Graphics2D) g);
Graphics2D graphics = (Graphics2D) g.create();
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
FontMetrics fm = c.getFontMetrics(c.getFont());
// 1) Draw the emphasis text.
graphics.setColor(model.isArmed()
? MacColorUtils.EMPTY_COLOR
: EmphasizedLabelUI.DEFAULT_EMPHASIS_COLOR);
BasicGraphicsUtils.drawStringUnderlineCharAt(graphics, text, -1,
textRect.x, textRect.y + 1 + fm.getAscent());
// 2) Draw the text.
graphics.setColor(model.isEnabled()
? EmphasizedLabelUI.DEFAULT_FOCUSED_FONT_COLOR
: EmphasizedLabelUI.DEFAULT_DISABLED_FONT_COLOR);
BasicGraphicsUtils.drawStringUnderlineCharAt(graphics, text, -1,
textRect.x, textRect.y + fm.getAscent());
graphics.dispose();
}
示例7: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) {
super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
v.paint(g, textRect);
} else {
// plain text
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
g.setColor(tabPane.getForegroundAt(tabIndex));
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
} else { // tab disabled
g.setColor(Color.BLACK);
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
}
}
}
示例8: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
FontMetrics fm = g.getFontMetrics();
int mnemIndex = b.getDisplayedMnemonicIndex();
/* Draw the Text */
if (model.isEnabled()) {
/*** paint the text normally */
g.setColor(b.getForeground());
} else {
/*** paint the text disabled ***/
g.setColor(getDisabledTextColor());
}
BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
示例9: drawStringUnderlineCharAt
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
public static void drawStringUnderlineCharAt(JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) {
Graphics2D g2D = (Graphics2D) g;
Object savedRenderingHint = null;
if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
}
if (getJavaVersion() >= 1.6) {
try {
Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2");
Class classParams[] = {JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE};
Method m = swingUtilities2Class.getMethod("drawStringUnderlineCharAt", classParams);
Object methodParams[] = {c, g, text, underlinedIndex, x, y};
m.invoke(null, methodParams);
} catch (Exception ex) {
BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
}
} else if (getJavaVersion() >= 1.4) {
BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, underlinedIndex, x, y);
} else {
BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
}
if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
}
}
示例10: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
/**
* Paints the specified text.
*
* @param g
* Graphics context.
* @param comp
* Component.
* @param textRect
* Text rectangle.
* @param text
* Text to paint.
* @param mnemonicIndex
* Mnemonic index.
* @param font
* Font to use.
* @param color
* Color to use.
* @param clip
* Optional clip. Can be <code>null</code>.
* @param transform
* Optional transform to apply. Can be <code>null</code>.
*/
private static void paintText(Graphics g, JComponent comp,
Rectangle textRect, String text, int mnemonicIndex,
java.awt.Font font, java.awt.Color color, java.awt.Rectangle clip,
java.awt.geom.AffineTransform transform) {
if ((text == null) || (text.length() == 0))
return;
Graphics2D g2d = (Graphics2D) g.create();
// workaroundBug6576507(g2d);
// RenderingUtils.installDesktopHints(g2d);
g2d.setFont(font);
g2d.setColor(color);
// fix for issue 420 - call clip() instead of setClip() to
// respect the currently set clip shape
if (clip != null)
g2d.clip(clip);
if (transform != null)
g2d.transform(transform);
BasicGraphicsUtils.drawStringUnderlineCharAt(g2d, text, mnemonicIndex,
textRect.x, textRect.y + g2d.getFontMetrics().getAscent());
g2d.dispose();
}
示例11: testDrawString
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
private static void testDrawString(boolean underlined) {
String str = "AOB";
JComponent comp = createComponent(str);
BufferedImage buffImage = createBufferedImage(WIDTH, HEIGHT);
Graphics2D g2 = buffImage.createGraphics();
g2.setColor(DRAW_COLOR);
g2.setFont(comp.getFont());
FontMetrics fontMetrices = comp.getFontMetrics(comp.getFont());
float width = BasicGraphicsUtils.getStringWidth(comp, fontMetrices, str);
float x = (WIDTH - width) / 2;
int y = 3 * HEIGHT / 4;
if (underlined) {
BasicGraphicsUtils.drawStringUnderlineCharAt(comp, g2, str, 1, x, y);
} else {
BasicGraphicsUtils.drawString(comp, g2, str, x, y);
}
g2.dispose();
float xx = BasicGraphicsUtils.getStringWidth(comp, fontMetrices, "A") +
BasicGraphicsUtils.getStringWidth(comp, fontMetrices, "O")/2;
checkImageContainsSymbol(buffImage, (int) xx, underlined ? 3 : 2);
}
示例12: paintEnabledText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
@Override
protected void paintEnabledText(JLabel label, Graphics g, String s,
int textX, int textY) {
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
if(fShadowColor!=null) {
g2.setColor(fShadowColor);
g2.setFont(label.getFont());
BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX, textY + 1);
}
g2.setColor(isParentWindowFocused(label)
? fFocusedTextColor : fUnfocusedTextColor);
BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX, textY);
g2.dispose();
}
示例13: paintDisabledText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
@Override
protected void paintDisabledText(JLabel label, Graphics g, String s, int textX, int textY) {
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
if(fShadowColor!=null) {
g2.setColor(fShadowColor);
g2.setFont(label.getFont());
BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX, textY + 1);
}
g2.setColor(DEFAULT_DISABLED_FONT_COLOR);
BasicGraphicsUtils.drawStringUnderlineCharAt(g2, s, -1, textX, textY);
g2.dispose();
}
示例14: paintText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect,
boolean isSelected) {
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
v.paint(g, textRect);
}
else {
// plain text
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
if (isSelected)
g.setColor(whiteColor);
else
g.setColor(tabPane.getForegroundAt(tabIndex));
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
}
else { // tab disabled
g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
}
}
}
示例15: paintDisabledText
import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
/**
* Draws the text for a disabled label, using the color defined in the
* {@link UIManager} defaults with the key
* <code>Label.disabledForeground</code>.
*
* @param l the label.
* @param g the graphics device.
* @param s the label text.
* @param textX the x-coordinate for the label.
* @param textY the y-coordinate for the label.
*/
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX,
int textY)
{
Color savedColor = g.getColor();
g.setColor(UIManager.getColor("Label.disabledForeground"));
int mnemIndex = l.getDisplayedMnemonicIndex();
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX,
textY);
else
g.drawString(s, textX, textY);
g.setColor(savedColor);
}