Creating a JButton Component from Action : Button « Swing JFC « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Swing JFC » Button 




Creating a JButton Component from Action
 

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;

public class Main {
  public static void main(String[] argvthrows Exception {
    Action action = new AbstractAction("Button Label") {
      // This method is called when the button is pressed
      public void actionPerformed(ActionEvent evt) {
        // Perform action...
      }
    };

    // Create the button from the action
    JButton button = new JButton(action);
  }
}

   
  














Related examples in the same category
1.Various Swing buttonsVarious Swing buttons
2.Responding to button pressesResponding to button presses
3.Putting buttons on an appletPutting buttons on an applet
4.Uses reflection to create groups of different types of AbstractButtonUses reflection to create groups of different types of AbstractButton
5.The Swing-ified button exampleThe Swing-ified button example
6.Create a JButton that does not show focusCreate a JButton that does not show focus
7.Demonstration of button events including Action, Item and Change event typesDemonstration of button events including Action, Item and Change event types
8.The event demonstration program for JToggleButtonThe event demonstration program for JToggleButton
9.An example of radio button menu items in actionAn example of radio button menu items in action
10.JToggleButton DemoJToggleButton Demo
11.A Selected ButtonA Selected Button
12.Button demo: Mnemonic, alignment and action command Button demo: Mnemonic, alignment and action command
13.Button action to change the panel backgroundButton action to change the panel background
14.HTML buttonHTML button
15.Creating a Multiline Label for a JButton Component
16.Lines are left justified. This label text will center the lines
17.Label text italicizes the second line
18.Changing the Label of a JButton Component
19.Ploygon ButtonPloygon Button
20.Simple Button UISimple Button UI
21.Displaying a Button with an Icon LabelDisplaying a Button with an Icon Label
22.Displaying a Button with a BorderDisplaying a Button with a Border
23.Displaying a Button with Varying IconsDisplaying a Button with Varying Icons
24.Displaying a Button with Various Label AlignmentsDisplaying a Button with Various Label Alignments
25.Working with Tooltip TextWorking with Tooltip Text
26.Sharing Models between Buttons
27.Sharing an Action between JButton ComponentsSharing an Action between JButton Components
28.Display Message
29.Button Html DemoButton Html Demo
30.Swing Button DemoSwing Button Demo
31.LoadSave: Button actionLoadSave: Button action
32.Button with ICON and Multiline Button with ICON and Multiline
33.Action Button SampleAction Button Sample
34.Mnemonic SampleMnemonic Sample
35.Swing Default ButtonSwing Default Button
36.Button Action SampleButton Action Sample
37.Button icons, a default button, HTML in a button,and button mnemonics.
38.Adding a Rollover and Pressed Icon to a JButton Component
39.Adding a Disabled Icon to a JButton Component
40.Setting the Gap Size Between the Label and Icon in a JButton Component
41.Moving the Icon in a JButton Component
42.Adding an Icon to a JButton Component
43.Moving the Label/Icon Pair in a JButton Component
44.If the action does not have an icon or a different icon must be used, add or change the icon using setIcon():
45.Dynamically update the appearance of a component
46.Simple ToggleButton SampleSimple ToggleButton Sample
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.