本文整理匯總了Java中javax.swing.AbstractButton.getSize方法的典型用法代碼示例。如果您正苦於以下問題:Java AbstractButton.getSize方法的具體用法?Java AbstractButton.getSize怎麽用?Java AbstractButton.getSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.AbstractButton
的用法示例。
在下文中一共展示了AbstractButton.getSize方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: paintBackground
import javax.swing.AbstractButton; //導入方法依賴的package包/類
protected void paintBackground(Graphics2D g, AbstractButton b) {
Dimension size = b.getSize();
Insets insets = b.getInsets();
Insets margin = b.getMargin();
if( null == insets || null == margin )
return;
g.fillRect(insets.left - margin.left,
insets.top - margin.top,
size.width - (insets.left-margin.left) - (insets.right - margin.right),
size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
}
示例2: paintButtonPressed
import javax.swing.AbstractButton; //導入方法依賴的package包/類
@Override
protected void paintButtonPressed(Graphics g, AbstractButton c) {
if (c.isContentAreaFilled()) {
Graphics2D g2d = (Graphics2D) g;
Dimension size = c.getSize();
Composite oldComposite = g2d.getComposite();
Color oldColor = g2d.getColor();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, size.width, size.height);
g2d.setComposite(oldComposite);
g2d.setColor(oldColor);
}
}
示例3: paint
import javax.swing.AbstractButton; //導入方法依賴的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));
}
}
}
示例4: paint
import javax.swing.AbstractButton; //導入方法依賴的package包/類
@Override
public synchronized void paint(Graphics g, JComponent c)
{
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
Dimension d = b.getSize();
g.setFont(c.getFont());
FontMetrics fm = g.getFontMetrics();
Icon icon = mIconUnchecked;
if( model.isPressed() && model.isSelected() )
{
icon = mIconPressedChecked;
}
else if( model.isPressed() && !model.isSelected() )
{
icon = mIconPressedUnchecked;
}
else if( !model.isPressed() && model.isSelected() )
{
icon = mIconChecked;
}
int x = 0;
int y = (d.height - icon.getIconHeight()) / 2;
icon.paintIcon(c, g, x, y);
if( b.isEnabled() )
{
g.setColor(mTextNormal);
}
else
{
g.setColor(mTextDisabled);
}
String caption = b.getText();
x = icon.getIconWidth() + mTextIconGap;
y = (d.height + fm.getAscent()) / 2;
g.drawString(caption, x, y);
}