当前位置: 首页>>代码示例>>Java>>正文


Java JButton.setEnabled方法代码示例

本文整理汇总了Java中javax.swing.JButton.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java JButton.setEnabled方法的具体用法?Java JButton.setEnabled怎么用?Java JButton.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JButton的用法示例。


在下文中一共展示了JButton.setEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setButtonState

import javax.swing.JButton; //导入方法依赖的package包/类
static void setButtonState(Container c, String buttonString,boolean flag ) {
int len = c.getComponentCount();
for (int i = 0; i < len; i++) {
  Component comp = c.getComponent(i);

  if (comp instanceof JButton) {
    JButton b = (JButton) comp;

    if ( buttonString.equals(b.getText()) ) {
        b.setEnabled(flag);
    }

  } else if (comp instanceof Container) {
      setButtonState((Container) comp, buttonString, flag);
  }
}
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:18,代码来源:CdavisFrameBlobDetector.java

示例2: setupResultsNavigator

import javax.swing.JButton; //导入方法依赖的package包/类
@SuppressWarnings("nls")
private JComponent setupResultsNavigator()
{
	countLabel = new JLabel();
	firstPage = new JButton("<<");
	prevPage = new JButton("<");
	nextPage = new JButton(">");
	lastPage = new JButton(">>");

	firstPage.setEnabled(false);
	prevPage.setEnabled(false);
	nextPage.setEnabled(false);
	lastPage.setEnabled(false);

	firstPage.addActionListener(this);
	prevPage.addActionListener(this);
	nextPage.addActionListener(this);
	lastPage.addActionListener(this);

	final int width1 = firstPage.getPreferredSize().width;
	final int height = firstPage.getPreferredSize().height;
	final int[] rows = {height,};
	final int[] cols = {TableLayout.FILL, width1, width1, width1, width1,};

	JPanel all = new JPanel(new TableLayout(rows, cols));

	all.add(countLabel, new Rectangle(0, 0, 1, 1));
	all.add(firstPage, new Rectangle(1, 0, 1, 1));
	all.add(prevPage, new Rectangle(2, 0, 1, 1));
	all.add(nextPage, new Rectangle(3, 0, 1, 1));
	all.add(lastPage, new Rectangle(4, 0, 1, 1));

	return all;
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:KeyResourcesTab.java

示例3: getTableCellEditorComponent

import javax.swing.JButton; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
	final Component c = super.getTableCellEditorComponent(table, value, isSelected, row, column);
	final JButton button = new JButton("?");
	button.setMargin(new Insets(0, 0, 0, 0));
	button.setToolTipText(Column.WHO_IS.getLabel());
	button.setPreferredSize(new Dimension(Column.WHO_IS.getWidth(), c.getHeight()));
	button.setMaximumSize(button.getPreferredSize());
	if (Env.INSTANCE.getOs() == OS.win) {
		button.setBorder(null);
	}
	button.setEnabled(!_searching);
	button.addActionListener(e -> {
		final RoutePoint point = _route.getRoute().get(_table.convertRowIndexToModel(row));
		WhoIsPanel.showWhoIsDialog(RouteTablePanel.this, _services, point);
		if (table.isEditing()) {
			table.getCellEditor().stopCellEditing();
		}
		_whois.clear();
	});
	return button;
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:23,代码来源:RouteTablePanel.java

示例4: ButtonDemo

import javax.swing.JButton; //导入方法依赖的package包/类
public ButtonDemo() {
    ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
    ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
    ImageIcon rightButtonIcon = createImageIcon("images/left.gif");

    b1 = new JButton("Disable middle button", leftButtonIcon);
    b1.setVerticalTextPosition(AbstractButton.CENTER);
    b1.setHorizontalTextPosition(AbstractButton.LEADING); // aka LEFT, for
                                                          // left-to-right
                                                          // locales
    b1.setMnemonic(KeyEvent.VK_D);
    b1.setActionCommand("disable");

    b2 = new JButton("Middle button", middleButtonIcon);
    b2.setVerticalTextPosition(AbstractButton.BOTTOM);
    b2.setHorizontalTextPosition(AbstractButton.CENTER);
    b2.setMnemonic(KeyEvent.VK_M);

    b3 = new JButton("Enable middle button", rightButtonIcon);
    // Use the default text position of CENTER, TRAILING (RIGHT).
    b3.setMnemonic(KeyEvent.VK_E);
    b3.setActionCommand("enable");
    b3.setEnabled(false);

    // Listen for actions on buttons 1 and 3.
    b1.addActionListener(this);
    b3.addActionListener(this);

    b1.setToolTipText("Click this button to disable the middle button.");
    b2.setToolTipText("This middle button does nothing when you click it.");
    b3.setToolTipText("Click this button to enable the middle button.");

    // Add Components to this container, using the default FlowLayout.
    add(b1);
    add(b2);
    add(b3);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:38,代码来源:ButtonDemo.java

示例5: updateLabelEtcFromList

import javax.swing.JButton; //导入方法依赖的package包/类
/** Updates label and enables/disables ok button. */
private static void updateLabelEtcFromList (JTextField field, JList list, List dirs, JButton okButton) {
    int idx = list.getSelectedIndex ();
    if (idx == -1) {
        field.setText (" "); // NOI18N
        field.getAccessibleContext().setAccessibleName(" ");
        okButton.setEnabled (false);
    } else {
        File dir = (File) dirs.get(idx);
        field.setText (NbBundle.getMessage(PackagePanel.class, "LBL_dirWillBe", dir.getAbsolutePath ()));
        field.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PackagePanel.class, "LBL_dirWillBe", dir.getAbsolutePath ()));
        okButton.setEnabled (true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:PackagePanel.java

示例6: createDisposeButton

import javax.swing.JButton; //导入方法依赖的package包/类
protected Component createDisposeButton() {
	closeB = new JButton("Dispose");
	closeB.addActionListener(this);
	closeB.setActionCommand("closeB");
	closeB.setEnabled(false);
	return closeB;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:8,代码来源:CustomDB.java

示例7: createAndShowTestDialog

import javax.swing.JButton; //导入方法依赖的package包/类
private static void createAndShowTestDialog(String description,
        String failMessage, Runnable action) {
    final JDialog dialog = new JDialog();
    dialog.setTitle("Test: " + (++testCount));
    dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);
    final JButton testButton = new JButton("Print Table");
    final JButton passButton = new JButton("PASS");
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
    });
    final JButton failButton = new JButton("FAIL");
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        throw new RuntimeException(failMessage);
    });
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        action.run();
        passButton.setEnabled(true);
        failButton.setEnabled(true);
    });
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);
    dialog.pack();
    dialog.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ImageableAreaTest.java

示例8: open

import javax.swing.JButton; //导入方法依赖的package包/类
@NbBundle.Messages({
    "BranchSelector.okButton.text=&OK",
    "BranchSelector.title=Select Branch"
})
public boolean open () {
    okButton = new JButton();
    org.openide.awt.Mnemonics.setLocalizedText(okButton, Bundle.BranchSelector_okButton_text());
    dd = new DialogDescriptor(panel, Bundle.BranchSelector_title(), true,
            new Object[] { okButton, DialogDescriptor.CANCEL_OPTION }, okButton,
            DialogDescriptor.DEFAULT_ALIGN, null, null);
    revisionPicker.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange (PropertyChangeEvent evt) {
            if (evt.getPropertyName() == RevisionDialogController.PROP_VALID) {
                setRevisionValid(Boolean.TRUE.equals(evt.getNewValue()));
            } else if (evt.getPropertyName() == RevisionDialogController.PROP_REVISION_ACCEPTED) {
                if (dd.isValid()) {
                    okButton.doClick();
                }
            }
        }
    });
    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
    okButton.setEnabled(false);
    d.setVisible(true);
    return okButton == dd.getValue();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:BranchSelector.java

示例9: open

import javax.swing.JButton; //导入方法依赖的package包/类
@NbBundle.Messages({
    "BranchSelector.okButton.text=&OK",
    "BranchSelector.title=Select Branch"
})
public boolean open () {
    okButton = new JButton();
    org.openide.awt.Mnemonics.setLocalizedText(okButton, Bundle.BranchSelector_okButton_text());
    dd = new DialogDescriptor(panel, Bundle.BranchSelector_title(), true,
            new Object[] { okButton, DialogDescriptor.CANCEL_OPTION }, okButton,
            DialogDescriptor.DEFAULT_ALIGN, null, null);
    revisionPicker.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange (PropertyChangeEvent evt) {
            if (evt.getPropertyName() == RevisionDialogController.PROP_VALID) {
                boolean valid = Boolean.TRUE.equals(evt.getNewValue());
                if (!valid) {
                    panel.errorLabel.setText(Bundle.SelectTrackedBranchPanel_error_noselection(branchName));
                } else if (branchName.equals(revisionPicker.getRevision().getRevision())) {
                    valid = false;
                    panel.errorLabel.setText(Bundle.SelectTrackedBranchPanel_error_samerevision(branchName));
                }
                if (valid) {
                    panel.errorLabel.setText(Bundle.SelectTrackedBranchPanel_info(branchName, revisionPicker.getRevision().getRevision()));
                }
                setRevisionValid(valid);
            } else if (evt.getPropertyName() == RevisionDialogController.PROP_REVISION_ACCEPTED) {
                if (dd.isValid()) {
                    okButton.doClick();
                }
            }
        }
    });
    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
    okButton.setEnabled(false);
    d.setVisible(true);
    return okButton == dd.getValue();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:SelectTrackedBranch.java

示例10: luoKomponentit

import javax.swing.JButton; //导入方法依赖的package包/类
private void luoKomponentit(Container container) {
    frame.setLayout(new GridLayout(3, 1));
    JTextField tuloskentta = new JTextField("0");
    container.add(tuloskentta);
    tuloskentta.setEnabled(false);
    JTextField syotekentta = new JTextField("");
    container.add(syotekentta);
 
    JButton plus = new JButton("+");
    JButton miinus = new JButton("-");
    JButton nollaa = new JButton("Z");
    JButton undo = new JButton("undo");
    
    Tapahtumankuuntelija kasittelija = new Tapahtumankuuntelija(plus, miinus, nollaa, undo, tuloskentta, syotekentta);
     
    plus.addActionListener(kasittelija);
    miinus.addActionListener(kasittelija);
    nollaa.addActionListener(kasittelija);
    undo.addActionListener(kasittelija);
    nollaa.setEnabled(false);
    undo.setEnabled(false);
    JPanel paneli = new JPanel(new GridLayout(1, 4));
    paneli.add(plus);
    paneli.add(miinus);
    paneli.add(nollaa);
    paneli.add(undo);
    container.add(paneli);
}
 
开发者ID:mluukkai,项目名称:ohjelmistotuotanto2017,代码行数:29,代码来源:GraafinenLaskin.java

示例11: freeze

import javax.swing.JButton; //导入方法依赖的package包/类
public void freeze() {
	for (JButton b : buttons) {

		b.setEnabled(false);

	}

	MainPanel.instance.bTomcat.setEnabled(false);
	MainPanel.instance.bWebApp.setEnabled(false);
	// MainPanel.instance.bConsole.setEnabled(false);
	// MainPanel.instance.bErrorLog.setEnabled(false);
	t.setEnabled(false);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:15,代码来源:TomcatPanel.java

示例12: setup

import javax.swing.JButton; //导入方法依赖的package包/类
private void setup(ShuffleInterface<T> si, String labelText, boolean allowUpDown)
{
	enabled = true;

	if( labelText == null )
	{
		labelText = DEFAULT_TEXT;
	}

	JLabel text = new JLabel(labelText);
	si.setParent(this);
	entry = si;

	add = new JButton("Add");
	remove = new JButton("Remove");
	edit = new JButton("Update");
	edit.addActionListener(this);
	add.addActionListener(this);
	remove.addActionListener(this);
	edit.setEnabled(false);
	if( allowUpDown )
	{
		up = new JButton(new ImageIcon(getClass().getResource(UP_ICON)));
		down = new JButton(new ImageIcon(getClass().getResource(DOWN_ICON)));

		up.setEnabled(false);
		down.setEnabled(false);

		up.addActionListener(this);
		down.addActionListener(this);
	}

	model = new GenericListModel<T>();
	list = new JList(model);
	list.addListSelectionListener(this);

	listScroll = new JScrollPane(list);

	JComponent entryComponent = entry.getComponent();

	int height1 = entryComponent.getPreferredSize().height;
	int height2 = add.getPreferredSize().height;
	int width1 = remove.getPreferredSize().width;
	int width2 = text.getPreferredSize().width - width1;
	if( width2 < 0 )
	{
		width2 = 0;
	}

	int[] rows = new int[]{height1, height2, height2, height2, height2, height2, TableLayout.FILL};
	int[] columns = new int[]{width1, width2, TableLayout.FILL};
	TableLayout layout = new TableLayout(rows, columns, 5, 5);
	setLayout(layout);

	add(entryComponent, new Rectangle(0, 0, 3, 1));

	add(listScroll, new Rectangle(1, 1, 2, 5));

	add(add, new Rectangle(0, 1, 1, 1));
	add(remove, new Rectangle(0, 2, 1, 1));
	add(edit, new Rectangle(0, 3, 1, 1));

	if( allowUpDown )
	{
		add(up, new Rectangle(0, 4, 1, 1));
		add(down, new Rectangle(0, 5, 1, 1));
	}

	refreshButtons();
}
 
开发者ID:equella,项目名称:Equella,代码行数:71,代码来源:JShuffleEditList.java

示例13: createDropDownButton

import javax.swing.JButton; //导入方法依赖的package包/类
private JButton createDropDownButton() {
    Icon icon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/evaluator/drop_down_arrow.png", false);
    final JButton button = new DropDownButton();
    button.setIcon(icon);
    String tooltipText = NbBundle.getMessage(CodeEvaluatorUI.class, "CTL_Expressions_Dropdown_tooltip");
    button.setToolTipText(tooltipText);
    button.setEnabled(false);
    Dimension size = new Dimension(icon.getIconWidth() + 3, icon.getIconHeight() + 2);
    button.setPreferredSize(size);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setFocusable(false);
    AbstractAction action = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if ("pressed".equals(e.getActionCommand())) {
                JComponent jc = (JComponent) e.getSource();
                Point p = new Point(0, 0);
                SwingUtilities.convertPointToScreen(p, jc);
                if (!ButtonPopupSwitcher.isShown()) {
                    SwitcherTableItem[] items = createSwitcherItems();
                    ButtonPopupSwitcher.selectItem(jc, items, p.x, p.y);
                }
                //Other portion of issue 37487, looks funny if the
                //button becomes pressed
                if (jc instanceof AbstractButton) {
                    AbstractButton jb = (AbstractButton) jc;
                    jb.getModel().setPressed(false);
                    jb.getModel().setRollover(false);
                    jb.getModel().setArmed(false);
                    jb.repaint();
                }
            }
        } // actionPerformed

        @Override
        public boolean isEnabled() {
            return !getEditItemsList().isEmpty();
        }

    };
    action.putValue(Action.SMALL_ICON, icon);
    action.putValue(Action.SHORT_DESCRIPTION, tooltipText);
    button.setAction(action);
    return button;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:CodeEvaluatorUI.java

示例14: doTest

import javax.swing.JButton; //导入方法依赖的package包/类
private static void doTest(Runnable action) {
    String description =
      "JTable with rows will be displayed along with scrollbar.\n"
       + "Scroll the table. Verify no arifacts are shown and rows.\n"
       + " are correctly displayed.";
    final JDialog dialog = new JDialog();
    dialog.setTitle("ScrollArtifactTest ");
    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);
    final JButton testButton = new JButton("Create Table");
    final JButton passButton = new JButton("PASS");
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        if (frame != null) {
            frame.setVisible(false);
            frame.dispose();
        }
    });
    final JButton failButton = new JButton("FAIL");
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        if (frame != null) {
            frame.setVisible(false);
            frame.dispose();
        }
        throw new RuntimeException("Scrollbar artifact shown");
    });
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        action.run();
        passButton.setEnabled(true);
        failButton.setEnabled(true);
    });
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);
    dialog.pack();
    dialog.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:JTableScrollTest.java

示例15: doTest

import javax.swing.JButton; //导入方法依赖的package包/类
private static void doTest(Runnable action) {
    String description
            = " Visual inspection of print dialog is required.\n"
            + " Initially, a print dialog will be shown.\n "
            + " Please verify Selection radio button is disabled.\n"
            + " Press OK. Then 2nd print dialog will be shown.\n"
            + " Please verify the Selection radio button is disabled\n"
            + " in 2nd print dialog. If disabled, press PASS else press fail";

    final JDialog dialog = new JDialog();
    dialog.setTitle("printSelectionTest");
    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);
    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    final JButton failButton = new JButton("FAIL");
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail();
    });
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        action.run();
        passButton.setEnabled(true);
        failButton.setEnabled(true);
    });
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);
    dialog.pack();
    dialog.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:PrintDlgSelectionAttribTest.java


注:本文中的javax.swing.JButton.setEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。