本文整理汇总了Java中javax.swing.JButton.setAction方法的典型用法代码示例。如果您正苦于以下问题:Java JButton.setAction方法的具体用法?Java JButton.setAction怎么用?Java JButton.setAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JButton
的用法示例。
在下文中一共展示了JButton.setAction方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setLinkedText
import javax.swing.JButton; //导入方法依赖的package包/类
@Messages({
"LBL_Loading=<Loading>",
"LBL_Undefined=<Undefined>"
})
private void setLinkedText(JButton btn, String url, boolean loading) {
if (url == null) {
btn.setAction(null);
if (loading) {
btn.setText(LBL_Loading());
} else {
btn.setText(LBL_Undefined());
}
btn.setCursor(null);
} else {
btn.setAction(new LinkAction(url));
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btn.setText("<html><a href=\"\">" + url + "</a></html>");
}
}
示例2: setActions
import javax.swing.JButton; //导入方法依赖的package包/类
public void setActions(AbstractAction[] actions) {
if(actions != null) {
controlPanel.buttonPanel.removeAll();
for (int i = 0; i < actions.length; i++) {
JButton button = new JButton();
button.setAction(actions[i]);
button.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(button, org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir")); // NOI18N
controlPanel.buttonPanel.add(button);
}
revalidate();
}
}
示例3: getToolbarPresenter
import javax.swing.JButton; //导入方法依赖的package包/类
@Override
public Component getToolbarPresenter() {
if (popup != null) {
JButton button = DropDownButtonFactory.createDropDownButton(
(ImageIcon) getValue(SMALL_ICON),
popup
);
button.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
button.setAction(this);
return button;
} else {
return new JButton(this);
}
}
示例4: getToolbarPresenter
import javax.swing.JButton; //导入方法依赖的package包/类
@Override
public Component getToolbarPresenter() {
if (popupMenu != null) {
JButton button = DropDownButtonFactory.createDropDownButton(
(ImageIcon) getValue(SMALL_ICON),
popupMenu
);
button.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
button.setAction(this);
return button;
} else {
return new JButton(this);
}
}
示例5: setActionButton
import javax.swing.JButton; //导入方法依赖的package包/类
public void setActionButton(String button, Action action) {
for (JButton element : btnList) {
if (element.getText().equals(button)) {
element.setAction(action);
element.setText(button);
break;
}
}
}
示例6: setActionToolBar
import javax.swing.JButton; //导入方法依赖的package包/类
public void setActionToolBar(String toolItem, Action action) {
for (int i = 0; i < toolBar.getComponentCount(); i++) {
Component component = toolBar.getComponent(i);
if (component instanceof JButton) {
JButton item = (JButton) component;
String description = (String) item.getAction().getValue(Action.SHORT_DESCRIPTION);
if (description.equals(toolItem)) {
item.setAction(action);
break;
}
}
}
}
示例7: setActionButton
import javax.swing.JButton; //导入方法依赖的package包/类
public void setActionButton(String button, AbstractAction a) {
for (JButton element : btnList) {
try {
if (element.getText().equals(button)) {
a.putValue(Action.NAME, button);
element.setAction(a);
break;
}
} catch (ClassCastException e) {
System.err.println("DEBUG: Casting not allowed");
}
}
}
示例8: main
import javax.swing.JButton; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, URISyntaxException {
final HtmlComponent htmlComponent = new HtmlComponent();
final URI url = SwingDemo.class.getResource("/index.html").toURI();
String prefix = url.toString();
int cut = prefix.lastIndexOf('/');
prefix = prefix.substring(0, cut + 1);
JScrollPane scrollPane = new JScrollPane(htmlComponent);
htmlComponent.addInternalLinkPrefix(prefix);
Action loadIndexAction = new AbstractAction("Back") {
@Override
public void actionPerformed(ActionEvent event) {
htmlComponent.loadHtml(url);
}
};
loadIndexAction.actionPerformed(null);
JFrame frame = new JFrame("NativeHtml");
frame.setLayout(new BorderLayout());
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
JButton back = new JButton("Back");
back.setAction(loadIndexAction);
JPanel topPanel = new JPanel();
topPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
topPanel.add(back);
frame.getContentPane().add(topPanel, BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
}
示例9: createButton
import javax.swing.JButton; //导入方法依赖的package包/类
public JButton createButton(Action a)
{
JButton b = new JButton();
b.putClientProperty("displayActionText", Boolean.TRUE);
b.setAction(a);
return b;
}
示例10: 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;
}
示例11: addDistribution
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* Adds a distribution to the given panel
*
* @param name
* the name to be displayed on the label before the
* distribution
* @param key
* to which parameter number in the Burst Distribution this
* nested distribution corresponds
* @param intervalPanel
* the panel to which the distribution should be added
*/
protected void addDistribution(String name, int key,
JPanel intervalPanel) {
JLabel distributionNameLabel = new JLabel(name);
// Add the name of the distribution on a single line
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(10, 0, 0, 0); // top padding
c.gridwidth = GridBagConstraints.REMAINDER; // end row after this
// entry
c.fill = GridBagConstraints.HORIZONTAL;
// how to fill space when enlarging window vertically
c.weightx = 1.0;
c.weighty = 0.0;
// Add the distribution
intervalPanel.add(distributionNameLabel, c);
// Add the edit button
JButton but = new JButton("Edit");
but.setAction(new EditButtonAction(key));
// Specifies the button size to maintain its width in the case that
// probability text fields are hidden
// TODO check if the specified values are compatible with all
// graphical systems
but.setPreferredSize(new Dimension(65, 24));
c.insets = new Insets(0, 0, 0, 0); // No space between Name of
// distribution and Edit button
// do not finish row because also the label for the distribution has
// to be added
c.gridwidth = GridBagConstraints.RELATIVE;
c.fill = GridBagConstraints.HORIZONTAL; // reset to default
c.weightx = 0.0; // reset to default
c.weighty = 0.0;
// Add the button
intervalPanel.add(but, c);
JTextField distributionValueTextField = new JTextField();
// The name of the field is the parameter number
distributionValueTextField.setName("" + key);
// If the distribution != null display
if (current.getParameter(key).getValue() != null) {
distributionValueTextField.setText(current.getParameter(key)
.getValue().toString());
}
// The value is not editable directly
distributionValueTextField.setEditable(false);
c.gridwidth = GridBagConstraints.REMAINDER; // end row
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1.0;
c.weighty = 1.0;
intervalPanel.add(distributionValueTextField, c);
}
示例12: getHelpButton
import javax.swing.JButton; //导入方法依赖的package包/类
public static JButton getHelpButton(Action a) {
JButton button = getHelpButton();
button.setAction(a);
return button;
}
示例13: addDistribution
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* Adds a distribution to the given panel
* @param name the name to be displayed on the label before the distribution
* @param key to which parameter number in the Burst Distribution this nested distribution corresponds
* @param intervalPanel the panel to which the distribution should be added
*/
protected void addDistribution(String name, int key, JPanel intervalPanel) {
JLabel distributionNameLabel = new JLabel(name);
//Add the name of the distribution on a single line
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(10, 0, 0, 0); // top padding
c.gridwidth = GridBagConstraints.REMAINDER; // end row after this entry
c.fill = GridBagConstraints.HORIZONTAL;
//how to fill space when enlarging window vertically
c.weightx = 1.0;
c.weighty = 0.0;
//Add the distribution
intervalPanel.add(distributionNameLabel, c);
//Add the edit button
JButton but = new JButton("Edit");
but.setAction(new EditButtonAction(key));
//Specifies the button size to maintain its width in the case that probability text fields are hidden
//TODO check if the specified values are compatible with all graphical systems
but.setPreferredSize(new Dimension(65, 24));
c.insets = new Insets(0, 0, 0, 0); //No space between Name of distribution and Edit button
// don't finish row because also the label for the distribution has to be added
c.gridwidth = GridBagConstraints.RELATIVE;
c.fill = GridBagConstraints.HORIZONTAL; // reset to default
c.weightx = 0.0; // reset to default
c.weighty = 0.0;
//Add the button
intervalPanel.add(but, c);
JTextField distributionValueTextField = new JTextField();
//The name of the field is the parameter number
distributionValueTextField.setName("" + key);
//If the distribution != null display
if (current.getParameter(key).getValue() != null) {
distributionValueTextField.setText(current.getParameter(key).getValue().toString());
}
//The value is not editable directly
distributionValueTextField.setEditable(false);
c.gridwidth = GridBagConstraints.REMAINDER; // end row
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1.0;
c.weighty = 1.0;
intervalPanel.add(distributionValueTextField, c);
}