javax.swing.AbstractButton#getDisplayedMnemonicIndex ( )源码实例Demo

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

源代码1 项目: FlatLaf   文件: FlatButtonUI.java
public static void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text, Color foreground ) {
	FontMetrics fm = b.getFontMetrics( b.getFont() );
	int mnemonicIndex = FlatLaf.isShowMnemonics() ? b.getDisplayedMnemonicIndex() : -1;

	g.setColor( foreground );
	FlatUIUtils.drawStringUnderlineCharAt( b, g, text, mnemonicIndex,
		textRect.x, textRect.y + fm.getAscent() );
}
 
源代码2 项目: netbeans   文件: Mnemonics.java
public void propertyChange(PropertyChangeEvent evt) {
    AbstractButton b = (AbstractButton) evt.getSource();
    if (b.getDisplayedMnemonicIndex() == -1) {
        Integer mnemonic = (Integer) b.getClientProperty(PROP_MNEMONIC);
        Integer index = (Integer) b.getClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX);
        if (mnemonic != null && index != null && Utilities.compareObjects(b.getText(), b.getClientProperty(PROP_TEXT))) {
            b.setMnemonic(mnemonic);
            b.setDisplayedMnemonicIndex(index);
        }
    }
}
 
源代码3 项目: beautyeye   文件: WinUtils.java
/**
	 * Renders a text String in Windows without the mnemonic.
	 * This is here because the WindowsUI hiearchy doesn't match the Component heirarchy. All
	 * the overriden paintText methods of the ButtonUI delegates will call this static method.
	 * <p>
	 *
	 * @param g Graphics context
	 * @param b Current button to render
	 * @param textRect Bounding rectangle to render the text.
	 * @param text String to render
	 * @param textShiftOffset the text shift offset
	 */
	public static void paintText(Graphics g, AbstractButton b, 
			Rectangle textRect, String text,
			int textShiftOffset) {
//		FontMetrics fm = SwingUtilities2.getFontMetrics(b, g);
		FontMetrics fm = MySwingUtilities2.getFontMetrics(
				b, g);//* modified by Jack Jiang 为了非公开api的兼容性

		int mnemIndex = b.getDisplayedMnemonicIndex();
		// W2K Feature: Check to see if the Underscore should be rendered.
//		if (WindowsLookAndFeel.isMnemonicHidden() == true) {
		if (isMnemonicHidden() == true) {//* modified by jack jiang
			mnemIndex = -1;
		}
//
//		XPStyle xp = XPStyle.getXP();
//		if (xp != null && !(b instanceof JMenuItem)) 
//		{
//			paintXPText(b, g, textRect.x + textShiftOffset, 
//					textRect.y + fm.getAscent() + textShiftOffset,
//					text, mnemIndex);
//		} 
//		else 
		{
			paintClassicText(b, g, textRect.x + textShiftOffset, 
					textRect.y + fm.getAscent() + textShiftOffset,
					text, mnemIndex);
		}
	}
 
源代码4 项目: beautyeye   文件: BEToggleButtonUI.java
/**
     * As of Java 2 platform v 1.4 this method should not be used or overriden.
     * Use the paintText method which takes the AbstractButton argument.
     *
     * @param g the g
     * @param c the c
     * @param textRect the text rect
     * @param text the text
     */
    protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    	AbstractButton b = (AbstractButton) c;                       
    	ButtonModel model = b.getModel();
    	FontMetrics fm = //SwingUtilities2
    					MySwingUtilities2.getFontMetrics(c, g);
    	int mnemonicIndex = b.getDisplayedMnemonicIndex();

    	/* Draw the Text */
    	if(model.isEnabled()) 
    	{
    		//=================== modified by jb2011 START
    		if(model.isSelected())//选中时使用不同的颜色
    			g.setColor(UIManager.getColor(getPropertyPrefix()+"focus"));
    		else
    			/*** paint the text normally */
    			g.setColor(b.getForeground());
    		//=================== modified by jb2011 END
    		
//    		SwingUtilities2 *不要直接调用该类(因为它是sun未公开api,1.5里与1.6及以后版它放在不同的包里,某天它会消失也说不好)
    		MySwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
    				textRect.x + getTextShiftOffset(),
    				textRect.y + fm.getAscent() + getTextShiftOffset());
    	}
    	else 
    	{
    		/*** paint the text disabled ***/
    		g.setColor(b.getBackground().brighter());
    		//SwingUtilities2 *不要直接调用该类(因为它是sun未公开api,1.5里与1.6及以后版它放在不同的包里,某天它会消失也说不好)
    		MySwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
    				textRect.x, textRect.y + fm.getAscent());
    		g.setColor(b.getBackground().darker());
    		//SwingUtilities2 *不要直接调用该类(因为它是sun未公开api,1.5里与1.6及以后版它放在不同的包里,某天它会消失也说不好)
    		MySwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
    				textRect.x - 1, textRect.y + fm.getAscent() - 1);
    	}
    }
 
源代码5 项目: RipplePower   文件: ButtonUI.java
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();
	if (model.isEnabled()) {
		g.setColor(b.getForeground());
	} else {
		g.setColor(getDisabledTextColor());
	}
	BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
 
源代码6 项目: RipplePower   文件: NavlinkUI.java
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();

	if (model.isEnabled()) {
		g.setColor(b.getForeground());
	} else {
		g.setColor(getDisabledTextColor());
	}
	BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
 
protected void paintText(
  Graphics g,
  AbstractButton b,
  Rectangle textRect,
  String text) {
  ButtonModel model = b.getModel();
  FontMetrics fm = g.getFontMetrics();
  int mnemonicIndex = b.getDisplayedMnemonicIndex();

  Color oldColor = g.getColor();

  /* Draw the Text */
  if (model.isEnabled()) {
    /** * paint the text normally */
    if (model.isSelected()) {
      g.setColor(selectedForeground);
    } else {
      g.setColor(unselectedForeground);
    }
  } else {
    g.setColor(unselectedForeground.darker());
  }

  //            
  BasicGraphicsUtils.drawStringUnderlineCharAt(
    g,
    text,
    mnemonicIndex,
    textRect.x + getTextShiftOffset(),
    textRect.y + fm.getAscent() + getTextShiftOffset());
  //
  //      } else {
  //        g.setColor(b.getParent().getBackground().brighter());
  //        BasicGraphicsUtils.drawStringUnderlineCharAt(
  //          g,
  //          text,
  //          mnemonicIndex,
  //          textRect.x,
  //          textRect.y + fm.getAscent());
  //        g.setColor(b.getParent().getBackground().darker());
  //        BasicGraphicsUtils.drawStringUnderlineCharAt(
  //          g,
  //          text,
  //          mnemonicIndex,
  //          textRect.x - 1,
  //          textRect.y + fm.getAscent() - 1);
  //      }
  g.setColor(oldColor);
}