Results 1 to 5 of 5
Thread: problem in my button
- 03-13-2010, 04:58 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 61
- Rep Power
- 0
-
Is this a Swing application, and are you using a JButton? Or is this AWT? SWT? Other? Details can mean a lot I'm afraid. If Swing, then you can set the root pane's default button via its setDefaultButton(JButton defaultButton) method.
Perhaps if you tell us more, we can tell you more. Much luck!
- 03-13-2010, 05:15 PM #3
Member
- Join Date
- Jan 2010
- Posts
- 61
- Rep Power
- 0
- 03-13-2010, 05:52 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
-
Have at it.
Java Code:import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class SwingFu { private static void createAndShowUI() { JButton nonDefaultBtn = new JButton("Not Default Button"); JButton defaultBtn = new JButton("Default Button"); final JTextField textfield = new JTextField(20); textfield.setEditable(false); textfield.setFocusable(false); ActionListener actionlistener = new ActionListener() { public void actionPerformed(ActionEvent e) { textfield.setText(e.getActionCommand() + " pressed"); } }; nonDefaultBtn.addActionListener(actionlistener); defaultBtn.addActionListener(actionlistener); JPanel panel = new JPanel(); panel.add(nonDefaultBtn); panel.add(defaultBtn); panel.add(textfield); JFrame frame = new JFrame("Main App"); // ***** HERE ***** // Get the JFrame's JRootPane // and Set the default button frame.getRootPane().setDefaultButton(defaultBtn); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } }
Similar Threads
-
Problem w/ ActionListener on a button
By qwertyuiop23 in forum AWT / SwingReplies: 2Last Post: 11-02-2009, 06:25 AM -
Problem with mozilla back button.
By shivakumari in forum Java ServletReplies: 3Last Post: 05-07-2009, 04:19 AM -
problem with back button of the browser.
By shivakumari in forum Java ServletReplies: 2Last Post: 03-25-2009, 07:41 AM -
problem on button
By udayforu_1986 in forum Java AppletsReplies: 1Last Post: 08-03-2008, 01:57 PM -
java applet button problem .. :( plz help
By i4gotmyid in forum New To JavaReplies: 0Last Post: 04-05-2008, 09:55 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks