Java Code Examples for javax.swing.AbstractButton#getDisplayedMnemonicIndex()

The following examples show how to use javax.swing.AbstractButton#getDisplayedMnemonicIndex() . 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 File: FlatButtonUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
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() );
}
 
Example 2
Source File: Mnemonics.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 3
Source File: WinUtils.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
	 * 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);
		}
	}
 
Example 4
Source File: BEToggleButtonUI.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
     * 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);
    	}
    }
 
Example 5
Source File: ButtonUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 6
Source File: NavlinkUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 7
Source File: IconPackagerButtonBarUI.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
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);
}