Action « Button « Java Swing Q&A





1. Switching on a string/implementing button actions    stackoverflow.com

Full disclaimer: I'm a CS student, and this question is related to a recently assigned Java program for Object-Oriented Programming. Although we've done some console stuff, this is the first time ...

2. How can I make a swing JButton repeat its action when it is held down?    stackoverflow.com

I am creating an touch screen application using Swing and have a request to change one of buttons so that it will behave like a keyboard when the button is held ...

3. How do I switch panels inside a frame depending on a button action?    stackoverflow.com

I have created an application that has a toolbar, menubar and content area. I have added the menu and toolbar to the application window, but I am stuck with displaying the ...

4. Java default form action or button    stackoverflow.com

In HTML forms, if you press 'enter' while in a text field the form will generally submit. I'm implementing a search panel in Java Swing, and I want to include the same ...

5. When i import from a file, click the next and previous buttons it is exporting data to my file? is there something wrong with my action listeners?    stackoverflow.com

public AddressBookApp(){

 frame = new JFrame("Address Book");
 frame.setSize(500, 400);
 frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

 panel = new JPanel();
 panel.setBackground(Color.gray);
 panel.setLayout(null);

 frame.add(panel);
 frame.setVisible(true);

 JMenuBar menubar = new JMenuBar();
 frame.setJMenuBar(menubar);
 JMenu file = new JMenu("File");
 menubar.add(file);
 JMenuItem ...

6. JButton with HTML named action and a mnemonic    stackoverflow.com

I have a JButton that is constructed using an Action and this action has a name that is contains html. I then go about setting the mnemonic on the JButton by first ...

7. Having a different action for each button dynamically created in a loop    stackoverflow.com

use this website a lot but first time posting. My program creates a number of buttons depending on the number of records in a file. E.g. 5 records, 5 buttons. The buttons are being ...

8. JButton action Listener    stackoverflow.com

Hey there, I'm searching for a Key Listener which always activates himself when the mouse is pressed down... for example if I keep pressing the button it will always write something ...

9. How to execute an Action without assigning it to JButton?    stackoverflow.com

I have a list of Actions (I got them form HTMLEditorKit), and I want to execute them simply from the code, not from gui. Is that possible?





10. Action listener for JButton array    stackoverflow.com

Let's say I have a program with 2D array of buttons, and when you click one of them it turns red. I didn't want to declare every single button seperately so ...

11. How to set action for close button?    stackoverflow.com

I've created a stand-alone java desktop application in Netbeans 6.9. I want to set the action for the close button of my application. I want to know how and where to ...

12. jbutton action, setIcon is being executed at the end of action    stackoverflow.com

I'm developing my first awt game. I'm trying to set an icon to a button when it is clicked (under some conditions). here is the concerning part of the code;

if (tileIsMemTile) ...

13. RE: JButton action listener is restarting entire program    stackoverflow.com

I am writing a GUI, and I have made custom buttons using null layouts, however whenever I am adding a action listener each time the button is pressed it is reloading ...

14. How to make use of action listeners in a different class?    stackoverflow.com

I am currently in a midst of developing an desktop application. I have the menu bar, which has the RUN command with the ALT-R mnemonic. Also, I have a RUN button ...

15. Instance of class is 'null' when action performed on netbeans GUI button    stackoverflow.com

I have a program complete with a number of classes which create complex objects, with custom variables and arrays of certain variables. I want to tie the functionality of these classes ...

16. How to add action listener that listens to multiple buttons    stackoverflow.com

I'm trying to figure out what i am doing wrong with action listeners. I'm following multiple tutorials and yet netbeans and eclipse are giving me errors when im trying to use ...





17. Fast Jbutton clicks results in no action    stackoverflow.com

Hey guys, I have a problem with a code that I've been writing. I have a JFrame that contains two buttons. Each of these buttons has an action. The problem I'm ...

18. Using ActionListener with JButton    stackoverflow.com

So, I am kind of new to programming interfaces with java. I have a menu of JButtons, where each JButton has an action associated with it (so I use new ...

19. ActionEvent in Java moves multiple buttons    stackoverflow.com

Okay so I am pretty much doing a crash course through creating a java application and am having an issue with executing an action. The program is the 15 puzzle, the ...

20. How to call from code like that button clicked?    stackoverflow.com

I have in code implement ActionListener for JToggleButton. How to call from code like that button clicked? (similar in javascript from code I can do $('button').click();) How to do this in Java? ...

21. Getting action events of buttons placed in a different component    stackoverflow.com

Is it possible to display a button outside the component in which it is placed. My question seems weird, but the situation is: I have a JFrame. I also have a ...

22. Java - Reusable button action handler concepts question    stackoverflow.com

First off - sorry for the wall of code but it's not too horrendous, just a framework for what I'm trying to explain. It runs without errors. The goal I'm making a ...

23. make a JButton action audible with a "click" sound    stackoverflow.com

Is there a built-in feature to make a Swing JButton audible. I am interested in a click or beep sound. I know I can invoke noise making code in ...

24. Every time i click a button it exits? (action listener)    stackoverflow.com

here is my code

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;

class Panell implements ActionListener {
    JButton button;
    JButton buttonTwo;
    JButton buttonThree;
    JButton ...

25. Loading an image via a button's action in a GUI    stackoverflow.com

I am trying to create project that will load an image by pressing an open file button on a tool bar, open a file chooser and will then load the chosen ...

26. How action a button to open a new pane in java for a GUI    stackoverflow.com

I am creating a GUI in which my home page has a button labelled "Welcome to the Panel" The point is that when you press on this button, it will navigate to ...

27. JButton's action called on a focusLost event. How is it possible?    stackoverflow.com

One of our customer reported an exception in our application. The problem is, I am completely unable to understand how this bug can be reproduced. Here is the code :

btn.addActionListener(new ActionListener() {
 ...

28. JButtons stopped performing actions    bytes.com

P: 1 Strife1817 Hey guys... Sorry to bother you with this, however, I am stumped. The project that I built - builds clean, and executes, however only one out of three ...

29. NetBeans GUI Builder - actions of JButtons not found after Refactor > copy    forums.netbeans.org

I did a Java Swing project and used that project as a starting base. I would like to keep that project untouched. It works and I just want to use it ...

30. jtabbedPane tabs with common action buttons    forums.netbeans.org

I am a Java beginner. I am hoping someone can help me with this. I have a jtabbedPane with 4 tabs and Jtables in each tab. I have New, Edit, Delete ...

31. urgent:Problem with action event of JButton    coderanch.com

hi freids, i designing a chat server. When i click on send button to send the message to other users via chatserver i m getting lots of exceptions like- at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125) at java.awt.Container.dispatchEventImpl(Container.java:1200) at java.awt.Window.dispatchEventImpl(Window.java:912) at java.awt.Component.dispatchEvent(Component.java:2499) at java.awt.EventQueue.dispatchEvent(EventQueue.java:319) etc. what should i do for it. its urgent. Please reply soon. Richa.

32. how to undo the last action printed on an applet using undo button    coderanch.com

Hi Srinivas, The example below might help you out. import java.awt.*; import java.awt.event.*; import javax.swing.*; class JFrameDraw extends JFrame { private int xLoc = 0; private int yLoc = 90; public JFrameDraw() { JPanel p = new JPanel(); JButton b = new JButton( "Draw" ); b.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { xLoc += 10; yLoc += ...

33. Modify JToolBar buttons and actions    coderanch.com

34. Help me ..how I can add an action to the button    coderanch.com

// [quote]Originally posted by NoOor nice: //Hello everybody //I have problem in adding an action to the buttons from separate class.. //I know how to add the actionListner class as inner class but if I want to ceate this class separate from other classes..how I can implement it.. //it show me many errors.. //this is the class I wrote...I don't know ...

36. Logic in button action...    coderanch.com

foundID.setText(" "); srchLabel.setText("Enter ID to search : "); srchTxt.setColumns(10); srchTxt.setText(""); srchTxt.setAlignmentX(3); srchTxt.setToolTipText("Input a Logon ID to search for."); JButton srchbtn = new JButton(" Search "); srchbtn.setToolTipText("Click here to Search for a used ID."); srchbtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if(srchTxt.getText() == ""){ foundID.setText("No ID passed for Search."); }else{ foundID.setText(new Searc4Id().S4Ids(srchTxt.getText())); } } });

37. button action command from keylistener    coderanch.com

I'm stumped. I have a nice button action event to run a login process for my app. My GUI has 2 fields (user id and password) and two buttons (Login and Cancel) My login button (bnLogin) has an actionhandler assigend to it to process its events. I want to add a keylistener to my password textfield so when the enter key ...

40. Adding actions to buttons    coderanch.com

41. JButton Action Listener Problem    coderanch.com

I tried this and it doesn't work. Am I putting it in the wrong place or is this not right. This cannot be this hard. I am missing something. Thank You. Here is my code maybe that will help. package Collections; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.awt.event.ActionListener; public class CollectionsJAC implements ActionListener { JTextArea text; ...

42. Nee Help!! JButton arrays action...    coderanch.com

43. How to set action on scrollpane back (<) and forward (>) button    coderanch.com

frnds, i want to scroll the records of a table through jscrollpane and show them into the following format in gui -- name : textfield address : textfield salary : textfield mobile no : textfield i want that as far i move the scrollpane in forward or backward direction, records in the text field should also be changed accordingly, for this ...

44. keyboard action of my JButton    coderanch.com

public class PasswordField extends JFrame { private JPanel passwordPanel; private JTextField userNameField; private JPasswordField passwordField; private JLabel userNameLabel; private JLabel passwordLabel; private JButton userConfirmationBtn; private Image icon; private ImageIcon frameBackground; private ImageIcon buttonBackground; public PasswordField() { initComponents(); } private void initComponents() { icon = new ImageIcon("c:/pics/mercuryLogo.jpg").getImage().getScaledInstance(300, 300, 0); frameBackground = new ImageIcon("c:/pics/passwordbck2.jpg"); buttonBackground = new ImageIcon("c:/pics/buttonbck"); userNameField = new JTextField(); passwordField ...

45. JButton action not called    coderanch.com

Hi I have added JButton in my panel. Further I have added actionlistener for that button as well. My problem is when I click on the button actionPerformed() method is not called. And if I move to that button using keyboard and press space, at that time actionPerformed() method is called. I am executing the program from Eclipse. I tried with ...

46. jbutton action performed    coderanch.com

One of the possible ways to do this would be to use the System#currentTimeMillis(); In pseudo code 1) Invoke currentTimeMillis() and retain the value as start time 2) Do stuff 3) Invoke currentTimeMillis() and retain the value as end time. Difference between end and start time would give you the time required to do stuff.

47. Button Action using netbeans    coderanch.com

Hi thanks for your replies and suggestions, i designed it , here the problem appears only when i extend from jpanel if i use jframe i get the desired output . i am able to run the code but see the out put only when i my class extend from jframe instead of jpanel .can you suggest why it happen . ...

48. JAVA GUI - Actions for Buttons/ActionListener/Event Handling    coderanch.com

Hello there, I'm trying on Gui exercises. One of them requires a simple GUI class for Vehicle. The GUI should have buttons for creating new SportsCar and new Van objects. and then should display the values of the instance variables of these variables. The GUI should also calculate and display the fuel consumption and acceleration of the vehicle objects that have ...

49. Calculate button action code    coderanch.com

Im new to Java , I don't know where to place the actionListener and actionEvents for the Calcbutton, any suggestions will be appreciated ? package javaapplication7; /** * * @author kwashing */ /** * * @author kwashing */ import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import java.text.NumberFormat; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JButton; public ...

50. Make Multiple jButtons do the same action.    coderanch.com

Hey guys, i need some help writing a program using a Swing interface. Basically the program does specific Math questions for topics that they teach in schools where i live. The problem I'm getting is that there's a button that will reset all the jTextFields and variables used in the program and since I am continually updating the program it gets ...

51. JButton Action Listner    java-forums.org

so here is my calculator, i am trying to get it to have action listners for all the buttons. i have tried and tried many tutorials online and cannot figure out how to successfully add action listeners to all the buttons and detect them. Any Ideas? Java Code: package Calculator; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.EtchedBorder; public class Main ...

52. refreshing my Buttons after executing an action    java-forums.org

purchaseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { while (e.getActionCommand().equals("PURCHASE")) { if (n1.Users.get(user).getMytiCredit() == 0) { text.setText("You need to recharge your Myti card first"); break; } if (e.getActionCommand().equals("PURCHASE") && user != null && stationListFrom.getSelectedIndex() != -1 && stationListTo.getSelectedIndex() != -1 && HoursListStart.getSelectedIndex() != -1 && MinutesListStart.getSelectedIndex() != -1 && HoursListEnd.getSelectedIndex() != -1 && HoursListEnd.getSelectedIndex() != -1) { text.setText("PURCHASE SELECTED"); text.setText(user + ...

53. actions for buttons    java-forums.org

Please help to implement actions for buttons, in attachment - you can see JPEG file you can see table 3 buttons (Insert, Update, Delete) I want to implement following: 1) when no checked at all - Update, Delete inactive, Insert - active 2) when checked any cell 2 buttons - Update, Delete active (update and delete depend on checking), Insert - ...

54. Button Action using netbeans ui    java-forums.org

Hi Forum, I am new to swing , netbeans . using netbeans ui components i set the button and text filed on the panel , set the button text to click , my intention is when i click on that button using mouse it have to show message " hai" in the text field . a simple example for my understand ...

55. Call action of JButton from another class    java-forums.org

56. Action-Listener with multiple Arguments? (Button Listener, specifically)    java-forums.org

Java Code: public void associateListeners() { String error; Class controllerClass; Method incrementMethod, decrementMethod; Class[] classArgs; Integer[] args; controllerClass = myController.getClass(); error = null; incrementMethod = null; decrementMethod = null; classArgs = new Class[1]; args = new Integer[1]; // Set argument types for method invokations (the "Russin'" way to spell it ;) try { classArgs[0] = Class.forName("java.lang.Integer"); } catch(ClassNotFoundException exception) ...

57. JButton action    java-forums.org

58. For some reason, my GUI is not recognizing multiple action listeners for buttons.    java-forums.org

For some reason, my GUI is not recognizing multiple action listeners for buttons. I need an answer ASAP, this program is due tomorrow night. I'm making a Blackjack GUI. The text-version of the game works fine, so the GUI is the only .java file that I'm having a problem with. When one button is programmed to have an action ...

59. Help With Java Buttons & Action Listener In A GUI.    java-forums.org

So for college I have to have this button that is set to a question mark, and then it is changed to a letter once it is clicked. I have the the button made, and set as a question mark, I have also implemented the action listener, but am not sure how to get the button to change once it's been ...

60. JButton and capturing its action    forums.oracle.com

The error message, as from the command prompt is Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at TemperatureUI.actionPerformed(TemperatureUI.java:45) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour ce) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown ...

61. Java Help - JFrame and JButton Actions    forums.oracle.com

Okay, that class extends JFrame as well right? Cause of what I understand there is 2 diffrent JFrames? Rather sure it is soo. As you know you have declared the variables welcomescreen and game in the constructor. And then you are trying to reach them from another method, actionPerformed(ActionEvent event); So, as you want to reach the variables from another method ...

63. jbutton and action event    forums.oracle.com

64. JRadioButton and JButton Syncup Action    forums.oracle.com

Hi All, A question under the provided subject. I have two buttons OK and CANCEL and 2 radiobuttons rb1 and rb2.After i select rb1 and OK i should get some message given in the System.out.println("").So how should i make a syncup for button and radiobutton since both handle different listeners(ActionListener,ItemListener)..??? regards, Viswanadh

65. call browser window JButton action    forums.oracle.com

67. How to perform action when JButton is pushed    forums.oracle.com

68. how do i use jbutton action listeners for mutiple frames(2frames)??    forums.oracle.com

//setting positions of components for new frame Insets insets = pane.getInsets(); Dimension size = save.getPreferredSize(); save.setBounds(100 , 50 , size.width, size.height); size = save2.getPreferredSize(); save2.setBounds(200 , 50 , size.width, size.height); size = cancel.getPreferredSize(); cancel.setBounds(400 , 50 , size.width, size.height); size = moviename.getPreferredSize(); moviename.setBounds(100 , 100 , size.width, size.height); size = moviename2.getPreferredSize(); moviename2.setBounds(200 , 100 , size.width, size.height); size = director.getPreferredSize(); director.setBounds(100, ...

69. Action Listeners and JButtons    forums.oracle.com

I have a button that I am trying to make and I want it to be able to use the action listeners that I get from JButton. However, I am using a different way for the user to click on the button. So, I do not use the old bounding box that jbutton uses. I am using a new one. So: ...