本文整理了Java中javax.swing.AbstractButton.getFont()
方法的一些代码示例,展示了AbstractButton.getFont()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractButton.getFont()
方法的具体详情如下:
包路径:javax.swing.AbstractButton
类名称:AbstractButton
方法名:getFont
暂无
代码示例来源:origin: stackoverflow.com
private static final String STR_NEWLINE = "<br />";
private FontRenderContext fontRenderContext = new FontRenderContext(new AffineTransform(), true, true);
private String getWrappedText(Graphics graphics, AbstractButton button, String str) {
if( str != null ) {
String text = str.replaceAll("<html><center>", "").replaceAll("</center></html>", "");
int width = button.getWidth();
Rectangle2D stringBounds = button.getFont().getStringBounds(text, fontRenderContext);
if ( !str.contains(STR_NEWLINE) && (width-5) < ((Double)stringBounds.getWidth()).intValue()) {
String newStr;
if( str.contains(" ") ) {
int lastIndex = str.lastIndexOf(" ");
newStr = str.substring(0, lastIndex)+STR_NEWLINE+str.substring(lastIndex);
} else {
int strLength = ((str.length()/3)*2);
newStr = str.substring(0, strLength)+STR_NEWLINE+str.substring(strLength);
}
return newStr;
}
}
return str;
}
代码示例来源:origin: com.synaptix/SynaptixSwing
/**
* Returns the baseline.
*
* @throws NullPointerException
* {@inheritDoc}
* @throws IllegalArgumentException
* {@inheritDoc}
* @see javax.swing.JComponent#getBaseline(int, int)
* @since 1.6
*/
public int getBaseline(JComponent c, int width, int height) {
super.getBaseline(c, width, height);
AbstractButton b = (AbstractButton) c;
String text = b.getText();
if (text == null || "".equals(text)) { //$NON-NLS-1$
return -1;
}
FontMetrics fm = b.getFontMetrics(b.getFont());
layout(b, fm, width, height);
return fm.getAscent();
}
代码示例来源:origin: freeplane/freeplane
static void scaleIcon(final AbstractButton actionComponent) {
final Icon icon = actionComponent.getIcon();
final IconFactory imageIconFactory = IconFactory.getInstance();
if (icon != null && imageIconFactory.canScaleIcon(icon)) {
final Font font = actionComponent.getFont();
final int fontHeight = actionComponent.getFontMetrics(font).getHeight();
final Quantity<LengthUnits> iconHeight = new Quantity<LengthUnits>(1.2 * fontHeight, LengthUnits.px);
actionComponent.setIcon(FreeplaneIconFactory.toImageIcon(imageIconFactory.getScaledIcon(icon, iconHeight)));
}
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-swing-plaf
Font f = b.getFont();
if (b.isSelected()) {
代码示例来源:origin: net.java.dev.swing-layout/swing-layout
/**
* Returns the baseline for buttons.
*/
private int getCheckBoxBaseline(AbstractButton button, int height) {
FontMetrics fm = button.getFontMetrics(button.getFont());
resetRects(button, height);
// NOTE: that we use "a" here to make sure we get a valid value, if
// we were to pass in an empty string or null we would not get
// back the right thing.
SwingUtilities.layoutCompoundLabel(
button, fm, "a", button.getIcon(),
button.getVerticalAlignment(), button.getHorizontalAlignment(),
button.getVerticalTextPosition(),
button.getHorizontalTextPosition(),
viewRect, iconRect, textRect,
button.getText() == null ? 0 : button.getIconTextGap());
return textRect.y + fm.getAscent();
}
/**
代码示例来源:origin: violetumleditor/violetumleditor
protected void installDefaults(AbstractButton b)
{
super.installDefaults(b);
b.setOpaque(true);
b.setBorderPainted(false);
b.setRolloverEnabled(true);
b.setFont(b.getFont().deriveFont(Font.PLAIN));
b.setBorder(new EmptyBorder(VGAP, HGAP, VGAP, HGAP));
}
代码示例来源:origin: net.java.dev.swing-layout/swing-layout
/**
* Returns the baseline for buttons.
*/
private int getButtonBaseline(AbstractButton button, int height) {
FontMetrics fm = button.getFontMetrics(button.getFont());
resetRects(button, height);
// NOTE: that we use "a" here to make sure we get a valid value, if
// we were to pass in an empty string or null we would not get
// back the right thing.
SwingUtilities.layoutCompoundLabel(
button, fm, "a", button.getIcon(),
button.getVerticalAlignment(), button.getHorizontalAlignment(),
button.getVerticalTextPosition(),
button.getHorizontalTextPosition(),
viewRect, iconRect, textRect,
button.getText() == null ? 0 : button.getIconTextGap());
return textRect.y + fm.getAscent() + 1;
}
代码示例来源:origin: violetumleditor/violetumleditor
protected void installDefaults(AbstractButton b)
{
super.installDefaults(b);
b.setOpaque(false);
b.setBorderPainted(false);
b.setRolloverEnabled(true);
b.setFont(b.getFont().deriveFont(Font.PLAIN));
}
代码示例来源:origin: net.java.dev.swing-layout/swing-layout
/**
* Returns the baseline for buttons.
*/
private static int getButtonBaseline(AbstractButton button, int height) {
FontMetrics fm = button.getFontMetrics(button.getFont());
resetRects(button, height);
String text = button.getText();
if (text != null && text.startsWith("<html>")) {
return -1;
}
// NOTE: that we use "a" here to make sure we get a valid value, if
// we were to pass in an empty string or null we would not get
// back the right thing.
SwingUtilities.layoutCompoundLabel(
button, fm, "a", button.getIcon(),
button.getVerticalAlignment(), button.getHorizontalAlignment(),
button.getVerticalTextPosition(),
button.getHorizontalTextPosition(),
viewRect, iconRect, textRect,
text == null ? 0 : button.getIconTextGap());
if (isAqua()) {
return textRect.y + fm.getAscent() + 1;
}
return textRect.y + fm.getAscent();
}
代码示例来源:origin: com.github.insubstantial/flamingo
protected void configureRenderer() {
this.buttonRendererPane = new CellRendererPane();
this.commandButton.add(buttonRendererPane);
this.rendererButton = createRendererButton();
this.rendererButton.setOpaque(false);
this.rendererSeparator = new JSeparator();
Font currFont = this.commandButton.getFont();
if ((currFont == null) || (currFont instanceof UIResource)) {
this.commandButton.setFont(this.rendererButton.getFont());
}
// special handling for Mac OS X native look-and-feel
this.rendererButton.putClientProperty("JButton.buttonType", "square");
}
代码示例来源:origin: com.jidesoft/jide-oss
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap, boolean isHorizontal) {
if (b.getComponentCount() > 0) {
return null;
}
Icon icon = b.getIcon();
String text = b.getText();
Font font = b.getFont();
FontMetrics fm = b.getFontMetrics(font);
Rectangle iconR = new Rectangle();
Rectangle textR = new Rectangle();
Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);
layoutCompoundLabel(b, fm, text, icon, isHorizontal,
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
viewR, iconR, textR, (text == null ? 0 : textIconGap));
/* The preferred size of the button is the size of
* the text and icon rectangles plus the buttons insets.
*/
Rectangle r = iconR.union(textR);
Insets insets = b.getInsets();
r.width += insets.left + insets.right;
r.height += insets.top + insets.bottom;
return r.getSize();
}
代码示例来源:origin: com.jtattoo/JTattoo
mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
g.setFont(b.getFont());
FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
if (model.isEnabled()) {
Color fc = b.getForeground();
代码示例来源:origin: org.swinglabs.swingx/swingx-core
String text = b.getText();
Font font = b.getFont();
FontMetrics fm = b.getFontMetrics(font);
代码示例来源:origin: com.jtattoo/JTattoo
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
g.setFont(b.getFont());
FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
int mnemIndex;
if (JTattooUtilities.getJavaVersion() >= 1.4) {
代码示例来源:origin: com.haulmont.thirdparty/swingx-core
String text = b.getText();
Font font = b.getFont();
FontMetrics fm = b.getFontMetrics(font);
代码示例来源:origin: com.jtattoo/JTattoo
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
ButtonModel model = b.getModel();
FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
int mnemIndex = (JTattooUtilities.getJavaVersion() >= 1.4) ? b.getDisplayedMnemonicIndex() : JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
int offs = 0;
代码示例来源:origin: org.swinglabs.swingx/swingx-all
String text = b.getText();
Font font = b.getFont();
FontMetrics fm = b.getFontMetrics(font);
代码示例来源:origin: com.jtattoo/JTattoo
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
ButtonModel model = b.getModel();
FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
int mnemIndex = (JTattooUtilities.getJavaVersion() >= 1.4) ? b.getDisplayedMnemonicIndex() : JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
if (model.isEnabled()) {
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
String text = b.getText();
Font font = b.getFont();
FontMetrics fm = b.getFontMetrics(font);
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
String text = b.getText();
Font font = b.getFont();
FontMetrics fm = b.getFontMetrics(font);
内容来源于网络,如有侵权,请联系作者删除!