本文整理匯總了Java中javax.swing.ButtonModel類的典型用法代碼示例。如果您正苦於以下問題:Java ButtonModel類的具體用法?Java ButtonModel怎麽用?Java ButtonModel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ButtonModel類屬於javax.swing包,在下文中一共展示了ButtonModel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: register
import javax.swing.ButtonModel; //導入依賴的package包/類
public static void register(Project project,
AntProjectHelper helper,
ReferenceHelper refHelper,
ListComponent list,
ButtonModel addJar,
ButtonModel addLibrary,
ButtonModel addAntArtifact,
ButtonModel remove,
ButtonModel moveUp,
ButtonModel moveDown,
ButtonModel edit,
Document libPath,
ClassPathUiSupport.Callback callback) {
register(project, helper, refHelper, list, addJar, addLibrary,
addAntArtifact, remove, moveUp, moveDown, edit, false, libPath,
callback);
}
示例2: setModel
import javax.swing.ButtonModel; //導入依賴的package包/類
@Override
public void setModel(ButtonModel model) {
ButtonModel oldModel = getModel();
if (oldModel != null) {
oldModel.removeChangeListener(this);
}
super.setModel(model);
ButtonModel newModel = getModel();
if (newModel != null) {
newModel.addChangeListener(this);
}
stateChanged(null);
}
示例3: getDefaultComponent
import javax.swing.ButtonModel; //導入依賴的package包/類
public Component getDefaultComponent(Container aContainer) {
Component c = getFirstComponent(aContainer);
if (c instanceof AbstractButton) {
ButtonModel bm = ((AbstractButton)c).getModel();
if (bm instanceof DefaultButtonModel) {
ButtonGroup bg = ((DefaultButtonModel)bm).getGroup();
Enumeration<AbstractButton> en = bg == null ? null : bg.getElements();
while (en != null && en.hasMoreElements()) {
AbstractButton ab = en.nextElement();
if (ab.isSelected()) return ab;
}
}
}
return c;
}
示例4: getListCellRenderer
import javax.swing.ButtonModel; //導入依賴的package包/類
@Override
@NonNull
public ListCellRenderer getListCellRenderer(
@NonNull final JList list,
@NonNull final Document nameDocument,
@NonNull final ButtonModel caseSensitive,
@NonNull final ButtonModel colorPrefered) {
Parameters.notNull("list", list); //NOI18N
Parameters.notNull("nameDocument", nameDocument); //NOI18N
Parameters.notNull("caseSensitive", caseSensitive); //NOI18N
return ItemRenderer.Builder.create(
list,
caseSensitive,
new FileDescriptorConvertor(nameDocument)).
setCamelCaseSeparator(CAMEL_CASE_SEPARATOR).
setColorPreferedProject(colorPrefered).
build();
}
示例5: testSetLocalizedTextWithModel
import javax.swing.ButtonModel; //導入依賴的package包/類
public void testSetLocalizedTextWithModel() throws Exception {
ButtonModel m = new DefaultButtonModel();
JButton b = new JButton();
Mnemonics.setLocalizedText(b, "Hello &There");
assertEquals("Hello There", b.getText());
if( Mnemonics.isAquaLF() ) {
assertEquals(0, b.getMnemonic());
assertEquals(-1, b.getDisplayedMnemonicIndex());
} else {
assertEquals('T', b.getMnemonic());
assertEquals(6, b.getDisplayedMnemonicIndex());
}
b.setModel(m);
assertEquals("Hello There", b.getText());
if( Mnemonics.isAquaLF() ) {
assertEquals(0, b.getMnemonic());
assertEquals(-1, b.getDisplayedMnemonicIndex());
} else {
assertEquals('T', b.getMnemonic());
assertEquals(6, b.getDisplayedMnemonicIndex());
}
}
示例6: paintIcon
import javax.swing.ButtonModel; //導入依賴的package包/類
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
JMenuItem b = (JMenuItem) c;
ButtonModel model = b.getModel();
g.translate(x, y);
boolean isSelected = model.isSelected();
boolean isEnabled = model.isEnabled();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// draw check mark
if (isSelected) {
g2.setStroke(CHECKBOX_STROKE);
if (isEnabled) {
g2.setColor(Colors.CHECKBOX_CHECKED);
} else {
g2.setColor(Colors.CHECKBOX_CHECKED_DISABLED);
}
g2.drawLine(2, 6, 5, 8);
g2.drawLine(5, 8, 9, 1);
}
g.translate(-x, -y);
}
示例7: getStyle
import javax.swing.ButtonModel; //導入依賴的package包/類
@Nonnull
@CheckReturnValue
public Style getStyle() {
final ButtonModel selected = styleGroup.getSelection();
return getStyleButtonStream()
.filter(button -> {
final ButtonModel model = button.getModel();
return model.equals(selected);
})
.map(button -> {
final String name = button.getText();
return Style.fromName(name, Style.NONE);
})
.findFirst()
.orElse(Style.NONE);
}
示例8: go
import javax.swing.ButtonModel; //導入依賴的package包/類
private void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = frame.getContentPane();
ButtonModel model = new DefaultButtonModel();
JCheckBox check = new JCheckBox("a bit broken");
check.setModel(model);
panel = new JPanel(new BorderLayout());
panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH);
panel.add(check);
contentPane.add(panel);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
}
示例9: paintBackground
import javax.swing.ButtonModel; //導入依賴的package包/類
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
if (model.isArmed()
|| (menuItem instanceof JMenu && model.isSelected())) {
paintButtonPressed(g, menuItem);
} else {
g.setColor(this.colorBg);
//g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());//(0, 0, gap + 1, menuItem.getHeight());
// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
// if (menuItem.getIcon() != null) {
// int gap = menuItem.getIcon().getIconWidth() + 2;
// g.setColor(this.darkColor);
// g.drawLine(gap, 0, gap, menuItem.getHeight());
// g.setColor(this.lightColor);
// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
// }
}
g.setColor(oldColor);
}
示例10: paint
import javax.swing.ButtonModel; //導入依賴的package包/類
/**
* Paints the Button
*
* @param g
* The graphics
* @param c
* The component
*/
@Override
public void paint(final Graphics g, final JComponent c) {
// super.paint(g, c);
final AbstractButton button = (AbstractButton) c;
button.setRolloverEnabled(true);
final ButtonModel model = button.getModel();
final Rectangle bounds = button.getBounds();
if (model.isPressed() && model.isArmed()) {
g.translate(1, 1);
super.paint(g, c);
g.translate(-1, -1);
downBorder.paintBorder(c, g, 0, 0, bounds.width, bounds.height);
} else if (button.isRolloverEnabled() && model.isRollover()) {
super.paint(g, c);
upBorder.paintBorder(c, g, 0, 0, bounds.width, bounds.height);
} else {
super.paint(g, c);
}
}
示例11: paintIcon
import javax.swing.ButtonModel; //導入依賴的package包/類
public void paintIcon(Graphics2D g,ButtonInfo info) {
AbstractButton button = info.button;
Icon icon = button.getIcon();
ButtonModel model = button.getModel();
if(model.isRollover() && button.getRolloverIcon()!=null)
icon = button.getRolloverIcon();
if(model.isPressed() && button.getPressedIcon()!=null)
icon = button.getPressedIcon();
if(model.isSelected() && button.getSelectedIcon()!=null)
icon = button.getSelectedIcon();
if(model.isRollover() && model.isSelected() && button.getRolloverSelectedIcon()!=null)
icon = button.getRolloverSelectedIcon();
if(isEnabled(button)==false && button.getDisabledIcon()!=null)
icon = button.getDisabledIcon();
if(isEnabled(button)==false && model.isSelected() && button.getDisabledIcon()!=null)
icon = button.getDisabledSelectedIcon();
if(icon!=null) {
g.setComposite(isEnabled(button) ? AlphaComposite.SrcOver : SRC_OVER_TRANSLUCENT);
icon.paintIcon(button, g, info.iconRect.x, info.iconRect.y);
}
}
示例12: paintText
import javax.swing.ButtonModel; //導入依賴的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);
}
}
示例13: paintBackground
import javax.swing.ButtonModel; //導入依賴的package包/類
@Override
public void paintBackground(Graphics2D g,ButtonInfo info) {
super.paintBackground(g, info);
if(info.button.isContentAreaFilled() || info.button.isBorderPainted()) {
ButtonModel model = info.button.getModel();
if(model.isSelected() || model.isArmed() || isSpacebarPressed(info.button)) {
g = (Graphics2D)g.create();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.clip( info.fill);
g.setColor(new Color(0,0,0,15));
g.setStroke(outline1);
g.draw( info.fill );
g.setStroke(outline2);
g.draw( info.fill );
g.setStroke(outline3);
g.draw( info.fill );
}
}
}
示例14: getPreImg
import javax.swing.ButtonModel; //導入依賴的package包/類
/**
* <pre>
* 根據按鈕狀態, 獲取當前狀態下圖片信息。
*
* According to the button state, access to the current
* state of the picture information.
* </pre>
*
* @param c <code>CheckBoxMenuItem</code> object.
* @param model <code>ButtonModel</code>
* @return <code>Image</code> when is selected return current image, otherwise return null.
*/
public Image getPreImg(Component c, ButtonModel model)
{
if (!model.isSelected())
{
return null;
}
if (model.isArmed())
{
return getRollverImg();
}
else
{
return getNormalImg();
}
}
示例15: paint
import javax.swing.ButtonModel; //導入依賴的package包/類
public void paint(Graphics g, JComponent c)
{
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
paintBg(g, (AbstractButton) c);
// 設置組件偏移,以達到視覺上的按下和彈起效果
// Set the component offsets to achieve visual depress and bounce
if(model.isPressed() && model.isArmed() && b.getIcon() == null)
{
g.translate(2, 1);
}
super.paint(g, c);
if(model.isPressed() && model.isArmed() && b.getIcon() == null)
{
g.translate(-2, -1);
}
}