Menu
  • HOME
  • TAGS

AbortProcessingException leaves stack trace in server log, how to disable this?

jsf,exception,logging,jsf-2,actionlistener

You can suppress the logging with a custom exception handler. As you're currently using OmniFaces FullAjaxExceptionHandler, you'd better extend it. In the handle() method, check if there's an exception and if it's an instance of AbortProcessingException. If so, then just ignore it and return directly from the exception handler. public...

JFileChooser crashes - Java 7

java,jbutton,actionlistener,jfilechooser

you are not handling the JFileChooser correctly for one thing. EDIT: changed this keyword to null. JFileChooser sumtin = new JFileChooser(); if(sumtin.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File filer = sumtin.getSelectedFile(); field.fromFile(filer.getName()); sudokuGrid.setText(field.toString()); mainWindow.revalidate(); mainWindow.repaint(); } ...

Java GUI - JButton opens another frame from another class

java,swing,jframe,jbutton,actionlistener

I managed to get the second frame displayed (including its contents) by adding a call to the run() method: ClientMenu menu = new ClientMenu(); menu.setVisible(true); menu.run(); That being said, there are quite some problems with your code: You have a main method in each of your classes. You should have...

Fetch data from textfield and display it in another textfield

java,swing,actionlistener

The simplest way is to declare your text area fields as class member variables, not inside the method. The other methods inside that class can then access them. JTextField t[]=new JTextField[8]; //created aray of objects private void CmbActionPerformed(java.awt.event.ActionEvent evt) { Then: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String a1; a1=t[0].getText(); Note...

Use non-local variables in actionlistener

java,icons,actionlistener

The error means exactly what it says: your array variable Btn is not final, so it cannot be accessed from the inner class. Making it final will fix the problem: final JToggleButton[] Btn = new ... Another solution would be moving the array into the class: public javax.swing.JToggleButton Btn1; public...

Java actionPerformed does not add the changed label until the GUI is resized

java,swing,label,actionlistener,jlabel

The lblResult label is initialized with "". When you set the value (a large text) there is no room for it inside the flow layout. I think you must set a more elaborated layout or a minimum width for the result label: Label width: setSize(400, 400); lblResult.setPreferredSize(new Dimension(200, 20)); Example...

Listener using JFrame in Java

java,swing,actionlistener

Some ways to fix this. Use a JDialog - provides modal blocking by default, Listener mechanism - call back with value later, or make your code blocking JDialog public class test extends JDialog { ... private int N; public int setVisible() { this.setVisible(true); return N; } public test() { super(null,...

Javascript - Too much click listener in app

javascript,jquery,events,actionlistener,onclicklistener

In terms of performance, the number of elements the event is bound to is where you'd see any issues. here is a jsperf test. You'll see that binding to many elements is much slower, even thou only one event is being bound in each case. The 3rd test in the...

Why isn't my actionListener working?

java,swing,jbutton,actionlistener

Your actionlistener works. But your button status is never add to the JFrame.

How to write a KeyListener for JavaFX

javafx,java-8,actionlistener,keylistener

From a JavaRanch Forum post. Key press and release handlers are added on the scene and update movement state variables recorded in the application. An animation timer hooks into the JavaFX pulse mechanism (which by default will be capped to fire an event 60 times a second) - so that...

Identify clicked p:commandButton in actionListener method

jsf,actionlistener,identifier,commandbutton

Use e.getComponent() ....... import javax.faces.event.ActionEvent; public class ........{ public String buttonId; public void UserActionListener (ActionEvent e) { System.out.println(e.getComponent().getClientId()); } } ...

Coding the Next and Previous button

java,io,actionlistener,next

Use List to store the data, so when your data look like say: a.csv - b.csv - c.csv So when you are reading b.csv, sp using listIterator, iterating to previous could be done using iterator.previous() i.e. reading a.csv while iterator.next() will lead you reading next file (forward) i.e. c.csv. Which...

getText for JTextField input after action event

java,swing,actionlistener,jtextfield

You defined your text fields twice. Once as an instance variable and once as a local variable. Get rid of the local variable. The code should be: //JTextField emailText = new JTextField(30); emailText = new JTextField(30); ...

ActionListener of JComboBox and initialize JPanel

java,swing,compiler-errors,actionlistener,jcombobox

I suggest you to make panel an attribute of your class. Then call panel such as YourClass.this.panel. public class YourClass { private JPanel panel; public YourClass() { // ... scene.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String choice = String.valueOf(scene.getSelectedItem()); if(choice.equals("Sceneria") || choice.equals("Scene")) { slider.setEnabled(false); YourClass.this.panel = new JPanel();...

How to specify an int from another class

java,actionlistener

What you're seeing here (the variables is always 0) is caused by the variables scope. In Java, variables have block-scope, meaning that they are valid only in the block (and any blocks in that block) that they where created in. A simple example: public void scope1(){ if (something){ int myint...

Why aren't the action listeners working

java,swing,jbutton,actionlistener

There isn't any problem with your ActionListeners (determined through printing "hello world" upon the button being pressed). The problem is that you never added SecurityNum to card1, which is why its text isn't getting cleared.

Calling startTimer Method Multiple Times(Java)

java,timer,actionlistener

It does not seem like good coding practice to leave a bunch of timers running in the background Generally, no, you don't want to have multiple Swing Timers running if you can help it. They won't scale well (the more you add, the worst things become). Where you trying...

actionPerformed confusion on button events

java,swing,actionlistener

Use else before the next if to chain them: public void actionPerformed(ActionEvent e) { if(e.getSource() == b[7][4] && selected == false) { b[7][4].setIcon(selected); selected = true; } else if(e.getSource() == b[7][4] && selected == true) { b[7][4].setIcon(king); selected = false; } } This way the second if clause is only...

How to pass an object argument to a method called in actionPerformed?

java,actionlistener

It seems to me that DisplayRecord can only display one Product at a time. If that is indeed the case, you can store that Product in a field and then access it from actionPerfomed().

Updating swing components within edt

java,multithreading,swing,actionlistener,event-dispatch-thread

So as long as I don't call the setVisible method the components are being made from the thread the instance was created Wrong. As long as you do not specifically create a new Thread or use a utility method (like for example the SwingUtilities#invoke... methods), each call is invoked...

GUI Animation: Slider Value between Action and Change classes?

java,swing,user-interface,actionlistener,jslider

Don't rely on static, it will blow up in your face... You are creating multiple instances SliderListener when you really should be only creating one and applying it to the JSlider (and in your case) the Timer. Having said that, I'd (personally) separate them... You're also creating a new Timer...

Exiting out of or quitting an actionListener

java,actionlistener

It seems that you only need to addActionListener(...) once on the button1 like this: state = 0 // state is initialized to 0 label1.setText("How many Submarines would you like"); button1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ switch(getState()){ case 0: //Your How-many-submarines logic goes here label1.setText("How many Friggates would you like"); setState(1);...

Check which jRadioButtons have been selected if they have been created in a loop

java,swing,actionlistener,jradiobutton

You could use setActionCommand("" + j) on each button to associate each button with its index, and then get the selected button's index in any group with bg.getSelection().getActionCommand(). You can then assign a single ActionListener to all the buttons in one group, and make sure the action listener knows which...

JFrame does not draw content when called inside ActionListener

java,swing,actionlistener,event-dispatch-thread

You're blocking the EDT! actionPerformed is executed on the EDT, so getSelectedIndex is also and wait.await() blocks it. Notice that once this happens, the first frame doesn't respond also (and minimizing and un-minimizing the frames will not even paint them). Even if the 2nd frame were to show, it would...

Changing label text using ActionListener

java,jbutton,actionlistener,jlabel,settext

Your problem is that you are not including the label.setText() method inside your if statements. Because of this it will execute every label.setText() call and keep overriding the text until it defaults to the final call in your method. It is better to use braces, even for one line if...

java.lang.InstantiationException: my.package.CustomActionListener with non-default constructor

jsf,serialization,actionlistener,commandbutton

Ignoring the strange design approach (feel free to ask a question on how to properly achieve the concrete functional requirement for which you possibly incorrectly thought that this would be the right solution), you can solve it by letting it implement Externalizable. This is an extension on Serializable which allows...

Create boolean to show true when correct JRadioButtons have been selected

java,actionlistener,jradiobutton

Working with your code, you could declare an array of booleans before the initial loop like so: int counter = x; boolean[] responses = new boolean[x] for(int i = 0; i < x; i++) { //new jpanel created for every row needed for the word JPanel jpLine = new JPanel(new...

Remove elements from pane when timer reaches 0?

java,timer,actionlistener,pane

You are using an AWT Action-Event. You want to remove an Item from the JavaFX-Pane. They run in different Threads. When you want to access JavaFX from the AWT Thread use: Platform.runLater(new Runnable() { @Override public void run() { //Your Access to Java FX } }); But maybe you can...

How to stop an actionListener from executing its code if the user chooses no on a confirm dialog box?

java,swing,actionlistener

Simply use an if statement and check the return state of the confirmation dialog... int result = JOptionPane.showConfirmDialog(this, "Are you sure you want to destory the world?", "Destory World", JOptionPane.YES_OPTION); if (result == JOptionPane.YES_OPTION) { // Blow it up } Of course, you could use the same technique, but use...

Figure drawn without function call?

java,swing,actionlistener

By default setVisible would be true. So, if you don't won't to show panel on load then make it false on constructor. And then make it visible when you hit Start. See below: class Move extends JPanel { static int x = 80, cv = 0; Move(){ setVisible(false); <-- Make...

doClick(), and Simon: All buttons will unpress at the same time instead of individually

java,swing,jbutton,actionlistener

Invoking doClick() may be an awkward choice for this, as it uses a Timer internally. Instead, use a JToggleButton, which will allow you to control each button's appearance based on its selected state using setSelected(). A complete example is shown in the game Buttons. In the ActionListener of your Swing...

actionlistener to Textfield

java,user-interface,actionlistener,credit-card

The field xyzField has not been initialized. Change this line: add(new JTextField(16)); by these: xyzField = new JTextField(16); add(xyzField); ...

How to return variable from within an if statement for use in a separate method?

java,swing,methods,actionlistener

Declare variables one, two, three, and four at a higher scope that is visible to the actionPerformed method you have. So for example, they could be instance variables in the class that randomNumber() and actionPerformed() make up. That way the variables maintain state between method calls, and are visible through...

Dynamically adding action listener to buttons

java,applet,actionlistener

I think you have some conceptual misunderstandings reflected in your code here. It's important to consider which component you are adding the ActionListener onto. At the moment, your code adds the ActionListener to the Gridl object extending Applet, rather than the button itself. It won't throw an exception, because that's...

Have the selected radio button to display in text area

java,swing,actionlistener,jradiobutton

If you've added the JRadioButtons to a ButtonGroup, then the ButtonGroup can give you the ButtonModel from the selected JRadioButton by calling getSelection() on it. And then you can get the model's actionCommand String (which has to be explicitly set for JRadioButtons). For instance, assuming a ButtonGroup called buttonGroup: private...

Why isn't my ActionListener working for my buttons?

java,css,swing,button,actionlistener

You declared your JButtons as class fields, but you never initialize them. Insted you create new JButton by: JButton btnsuit1 = new JButton(); so, the btnsuit1 in btnsuit1.setVisible(false) is probably null. Try to change btnsuit1 initialization on: btnsuit1 = new JButton(); It should work....

Passing “this” as a Method Argument - Clarification

java,swing,methods,this,actionlistener

this represents the current instance of your class. Toolbar class implements ActionListener interface, that means it provides an implementation of method actionPerformed. So, helloButton.addActionListener(this); becomes possible (try to remove implements ActionListener from class declaration, the code won't compile). Saying this, Toolbar instances can be considered as ActionListener objects and can...

ActionListener and for loop

java,swing,loops,for-loop,actionlistener

Why is your code currently not working, and what was probably wrong with your previous attempt. action1.addActionListener(roundLevelActionObj); action2.addActionListener(roundLevelActionObj); action3.addActionListener(roundLevelActionObj); This will add the same listener to each of your buttons. When you click on either of these buttons, an ActionEvent is generated and send to the ActionListener. When you have...

Java ActionListener displaying false output

java,actionlistener

It looks like you are setting the action listener to the wrong button. Try using answer.addActionListener() instead of answer2.addActionListener() in the action listener for the addition menu bar item.

How to launch a second JFrame from clicking a JButton?

java,swing,jbutton,actionlistener

You're adding listeners inside of listeners -- something that you don't want to do, since this means that new listeners will be added, each time an event occurs. Solution: don't add listeners inside of other event listeners but rather add the listeners once and in your code's constructor or initialization...

Unable to add text to JTextArea in Java from another function

java,function,static,actionlistener,jtextarea

textArea() is returning a new JTextArea everytime it is called. Therefore your buttonAddText() function is calling textArea() and adding text to a newly created text area that is not contained in the scroll pane. You need to pass a reference of the text area to the textScrollPane() and the buttonAddText()...

How to link JcheckBoxes to JtextFields when they are being dynamically generated?

java,swing,actionlistener,jtextfield,jcheckbox

One thing you could do is use the setName and getName methods of Component to save the index of the JCheckBox. projectPanels[i].setName(Integer.toString(i)); Then, in your state change listener. int i = Integer.valueOf(e.getName()); This gives you the index of the JTextField....

Same ActionListener for Different Buttons - Best Practices

java,swing,actionlistener

The best way? Probably not by most people's standards. In my eyes? Yeah, it's probably the best way. You made a reusable instance of an ActionListener because you use it more than once. To me it's the same thing as making the class extend ActionListener. Most recommended takes us into...

Looking for a simple way to change text in a JTextField with a button click

java,swing,button,actionlistener

import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class TranslatorFrame { public static void main(String[] args) { JFrame Words = new JFrame("Greetings Translator"); Words.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Did some research to find the line so the program // would...

ActionListener principles

java,swing,compiler-errors,actionlistener

so, why it is not working in the first case and working in second case.? Like the compiler message says, in the first example you didn't implement the ActionListener interface in your MainFrameAli2 class. You created an anonymous inner class which implements the ActionListener interface. This is not the...

Actionlistener outputing Jlist info to textarea

java,swing,actionlistener,jlist,thread-sleep

Right now only data you can read from list is name and surname, you can achieve by using ListSelectionListener: list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { text.setText(list.getSelectedValue().toString()); } }); ...

Java Nonogram (Checking Solutions) not working

java,swing,actionlistener

In Start: static JButton[][] gumbi = new JButton[11][11]; In Resitve String[] stetjeV = new String[10]; for (int i = 1; i < Start.gumbi.length; i++) { stevecC = 0; stetjeV[i] = ""; // NPE! because 10 is less than 11 Maybe here too: String[] stetjeS = new String[10]; And also in...

Incrementing value of an integer in JTextArea

java,swing,jbutton,actionlistener,jtextarea

In myFrames constructor, replace JTextArea area = new JTextArea(20,15); with area = new JTextArea(20,15);

Two JCheckbox sources?

java,swing,listener,actionlistener

The condition e.getSource() == genderM && e.getSource() == h60 Can never return true because the source is either genderM or h60. Perhaps you meant logical OR. e.getSource() == genderM || e.getSource() == h60 As an alternative, I'd ignore the source of the event, and use the state of the components...

Why won't my .isSelected() method work?

java,methods,awt,actionlistener

if i understand you right, you want do do something like this: //Method to change the text of the JRadion Buttons, what i'm trying to make work ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { if(b1.isSelected()){ b1.setText("Welcome"); } else if(b2.isSelected()){ b2.setText("Hello"); } } }; b1= new JRadioButton("green");...

Passing an Application Class Reference to Constructor (Java)

java,javascript-events,parameter-passing,actionlistener

You can use the keyword this to get a reference to the "current instance". I'm not sure which class you want to add it to, but here's an example that should demonstrate the idea: public class A { private B owner; public A(B owner) {this.owner = owner;} public void callOwnerDoSomething()...

How to handle addTextChangedListener on two EditText together?

android,layout,android-edittext,actionlistener

Create a function to enable signup button public void tryEnableSignUpButton(){ if(etUsername.getText().toString().lenght>=1 && (etPswd .getText().toString().lenght>=1 )){ btnSignup.setEnabled(true); } } Now after each @Override public void afterTextChanged(Editable s) { int userName = s.length(); if(userName >=1){ tryEnableSignUpButton(); } } @EDIT @Override public void onBackPressed() { trydisableLoginButton(); super.onBackPressed(); } ...

ActionListener for one of the Jbuttons doesn't get called

java,swing,jbutton,actionlistener

Here's what I think is happening. At the start, you create a ColorPanel, using ColorPanel() and add an ActionListener to its setbtn. Then, after the expression is entered in the top panel and its button is pressed, a new ColorPanel is made using ColorPanel(string). However, the new setbtn in the...

Using JRadioButton to display images

java,swing,actionlistener

You'd probably need to call revalidate and repaint after adding the picture labels, but a better solution would be to add a single JLabel in the constructor (along with your radio buttons) and simply use it's setIcon method to change the image import java.awt.FlowLayout; import java.awt.event.ActionListener; import javafx.event.ActionEvent; import javax.swing.ButtonGroup;...

JButton does not change a field value

java,swing,jframe,jbutton,actionlistener

When you run this: while (true) { if ((t.get())) break; } the thread will eat all cpu, making the UI unresponsive; to overcome, one easy way would be adding a sleep time inside the loop: while (true) { Thread.sleep(250); // sleep for 250 msecs if (t.get()) break; } Anyway it...

Issue about JComboBox with actionlistner

java,swing,actionlistener,jcombobox

You're using the ArrayList data to set the JComboBox's model (here likely a DefaultComboBoxModel), but then later changing the ArrayList's data shouldn't and likely won't change the model once it's been set (although for other collections there may be risk of that happening). Better to just go ahead and use...

Custom JDialog - Find out if OK was presed

java,swing,actionlistener,joptionpane,jdialog

The easiest option is to use the standard functionality, like this: int opt = JOptionPane.showOptionDialog(jf, "Do you really want to?", "Confirm", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if(opt == JOptionPane.OK_OPTION) { System.out.println("Ok then!"); } else { System.out.println("Didn't think so."); } If you really want to use your own dialog, as in...

JButton not performing it's Required Function in java

java,jbutton,actionlistener

You're shadowing variable button1. Replace JButton button1 = new JButton("CONVERT"); with button1 = new JButton("CONVERT"); ...

I want to update table when Button is clicked

java,swing,jtable,actionlistener,defaulttablemodel

Instead of doing this... String[] colNames = { "BAND", "Test1", "Test2", "Test3", "Test4", "Test5" }; DefaultTableModel model = new DefaultTableModel(data, colNames); table = new Table(model); Simply update the existing model DefaultTableModel model = (DefaultTableModel)table.getModel(); for (Object[] row : data) { model.addRow(row); } or simply DefaultTableModel model = (DefaultTableModel)table.getModel(); for (int...

Focus on the button using tab key and press enter

java,swing,netbeans,jbutton,actionlistener

Some look and feels (looking at you Metal) use the Space key as the "action key". A simple solution would be to use a different look at feel, personally, I prefer the system look and feel for this reason, it should work in ways that the user is use to...

How to execute another action while one action is executing?

java,swing,actionlistener

You need to execute your long running task in a separate Thread so you don't prevent the GUI from responding to events. Read the section from the Swing tutorial on Concurrency for more information. Maybe a SwingWorker is the easiest approach as it creates the Thread for you and notifies...

ActionListener Not Detecting Buttons?

javascript,actionlistener

From oracle's guide To write an Action Listener, follow the steps given below: Declare an event handler class and specify that the class either implements an ActionListener interface or extends a class that implements an ActionListener interface. For example: public class MyClass implements ActionListener { Register an instance of the...

JButton text won't update until other operations are done

java,swing,jbutton,actionlistener

If NotifyObserversSinogram() does not do Swing specific computations, just drop it in another thread: public void actionPerformed(ActionEvent e) { sinoButton.setText("Loading Sinogram"); new Thread() { public void run(){ NotifyObserversSinogram(); } }.start(); } If it does, see SwingWorker....

ActionListener for multi-dimensional array only works for first button?

java,arrays,swing,multidimensional-array,actionlistener

You appear to be re-randomizing things each time the ActionListener is pressed which does not sound like what your requirement calls for. Instead, you should assign the random buttons once in your constructor and not in the ActionListener. Perhaps create a List<JButton> that holds all of the selecteed nugget buttons,...

Is there any technical advantage of actionListner attribute over action attribute in h:commandButton?

jsf,jsf-2,action,actionlistener,commandbutton

This question was answered whithin the comments, So i will copy the response of BalusC: Nope. It's purely for demonstration purposes. It would only be beneficial if the outcome part was determined in action instead of in actionListener. Right now the handleMouseClick() action listener isn't reusable on different actions expecting...

What is an action command that is set by setActionCommand?

java,swing,awt,actionlistener

In fact, JButton redirects the specified action command to the ButtonModel. Here's the method that forwards to the ButtonModel, with comment. /** * Sets the action command string that gets sent as part of the * <code>ActionEvent</code> when the button is triggered. * * @param s the <code>String</code> that identifies...

try/catch block not working in actionlistener

java,user-interface,try-catch,actionlistener,jtextfield

So essentially I see three problems(including the ones that you aren't having problems with- yet): The function parseInt throws an exception but you are not catching it because it is not in the try block. You are catching the wrong exception so it will never be caught. You can read...

JFrame error actionperformed

java,swing,jframe,actionlistener,visibility

It looks like you have a name clash: frame3 is used for a class and a variable: frame3 frame3 = new frame3(); If your class is named frame3 I would rename it to Frame3....

Getting the Error: Cannot instantiate the type java.awt.event.ActionListener

java,swing,awt,instance,actionlistener

It's the line instruct.addActionListener(new ActionListener()); ActionListener is an interface that you have to implement in a subclass. In order for this to make sense, the simplest fix would be to change that line to instruct.addActionListener(this), and move it into the constructor, because your class already implements ActionListener. If you go...

ActionListener not responding?

java,swing,actionlistener

The problem is that your if (control == buy4) { ... } misses the closing bracket. So what you actually have is if ( control == buy1 ){ ... } ... if ( control == buy4 ){ if ( control == buy5 ){ ... } if ( control == buy6...

Use method as event listener instead of class

java,swing,actionlistener

If you're using Java 8, you can accomplish this using a lambda expression. btn1.addActionListener(e -> this.functionForBTN1()); Prior to Java 8, you could create an anonymous ActionListener to acomplish the same task. btn1.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ this.functionForBTN1(); } }); ...

Action Listener not working in a MVC application

java,model-view-controller,actionlistener

You add actionListener to Button created by default constructor, then in actionListener: optionsWindow = new OptionsWindow(mainWindow.getMainFrame()); You create new OptionsWindow, without connection to actionListener of SaveButton. So it is enought to add: if (ev.getSource() == mainWindow.optionsButton) { System.out.println("Options pressed"); optionsWindow = new OptionsWindow(mainWindow.getMainFrame()); optionsWindow.addOptionsButtonListener(new OptionsButtonListener()); //<-- once again add actionListener...

Buttons and paint method

java,swing,graphics,jbutton,actionlistener

You've got lots of major problems with this code including: Drawing directly within a JFrame's paint method, something fraught with problems as you risk messing up the JFrame's own complicated painting. Placing program logic within a painting method, a method you don't have full control over when or if it...

How to invoke button click without explicit click on that button

java,events,actionlistener,sphinx4

If pressing the button does more than just invoking the jButton1ActionPerformed method you showed here, use the doClick() method on the JButton object, which I'm guessing you called jButton1: jButton1.doClick(); You can also cut out the middleman and just call your method directly, like any other. (This will only work...

Have an ActionListener wait for a click event to occur

java,swing,actionlistener

You could use the MouseListener on your window(Jframe), and your ActionListener for your button, and use a global flag buttonClicked to keep a check if the button was clicked, and set it to false by default. buttonClicked = false; then in your action performed, public void actionPerformed(ActionEvent event) { if(event.getSource()...

Assign int to JButtons to make method more efficient?

java,swing,icons,jbutton,actionlistener

You could... Associate each JButton with an int via a Map of some kind... private Map<JButton, Integer> mapButtons; //... mapButtons = new HashMap<JButton, Integer>(25); mapButtons.put(cardOne, 1); Then you could just extract the integer value within the ActionListener public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JButton)...

Error: Reference not found. Binding an ActionListener method to a button in

jsf,parameter-passing,actionlistener,oracle-adf

Your actionListener can only have an ActionEvent as parameter (so remove everything else). If you want to send extra parameters, you can use the following logic: On the page: <af:button text="button" id="cb1" actionListener="#{myBean.myActionListener}"> <f:attribute name="param" value="value"/> </af:button> In the bean: public void myActionListener(ActionEvent actionEvent) { String param = (String)actionEvent.getComponent().getAttributes().get("param"); }...

Java import wildcard not importing everything inside package

java,import,awt,actionlistener,wildcard

Here is the definition of type-import-on-demand in the Java Language Specification: A type-import-on-demand declaration allows all accessible types of a named package or type to be imported as needed. TypeImportOnDemandDeclaration: import PackageOrTypeName . * ; It is important to understand the terminology: "all accessible types of a named package" means...

Highlight text in JComboBox then erase it if user input something

java,swing,text,actionlistener,jcombobox

You need to add the logic to the editor of the combo box which happens to be a text field. The basic code would be something like: ComboBoxEditor editor = comboBox.getEditor(); JTextField textField = (JTextField)editor.getEditorComponent(); textField.addFocusListener( new FocusListener() { public void focusGained(final FocusEvent e) { SwingUtilities.invokeLater(new Runnable() { public void...

How to use swing timer?

java,swing,timer,actionlistener

Get rid of the for loops in your paintComponent method. Note that painting methods should not change object state. Instead the timer's actionPerformed method gets repeatedly called -- advance your counter or x/y variables there, and then call repaint(). e.g., private int x; private int y; public void paintComponent(Graphics g)...

Add listener to JPanel that will be only called onload

java,swing,actionlistener

I see you are using a CardLayout and you want to know when a card is made visible. You can use a HierarchyListener on your panel. The basic code to listen for the panel becoming visible would be: @Override public void hierarchyChanged(HierarchyEvent e) { JComponent component = (JComponent)e.getSource(); if ((HierarchyEvent.SHOWING_CHANGED...

Detect clicks on button array with a single method

arrays,methods,jbutton,actionlistener

Maybe something like that (using jQuery for convenience but you can do it with Vanilla JS too): Your HTML: <div id="buttonsHolder"> <button data-num=1>1</button> <button data-num=2>2</button> <button data-num=3>3</button> ... <button data-num=4>4</button> </div> Your JavaScript: $('#buttonsHolder').on('click', 'button', (function(evt){ var buttonNum = $(this).attr('data-num'); // Now, buttonNum variable holds the button number has clicked....

Calling a Java AbstractAction from a button/mouse release

java,swing,jbutton,actionlistener,abstract-action

One thing that many people miss when dealing with key bindings, is the fact that you can register for either a "press" or "release" event (press been the default). So in your case, you need to do both. The "press" event should "arm" AND "press" the button, the "release" should...

Java Swing Timer infinite loop

java,swing,timer,actionlistener,infinite-loop

Every time the timer calls you back you create a new timer and start it. This includes after you call timer.stop()! You need to only create the new timer if you want to continue. Really you should look at another method for doing this rather than constantly recreating timers though....

Camera listener service?

android,camera,actionlistener

Can this be done? Not really. First, there is no singular "native camera app". There are ~1.5 billion Android devices, spanning thousands of models. These will come with hundreds of different "native camera app" implementations. Plus, users can install other camera apps and use those. None of them necessarily...

Adding textfield and label on mouse click not working Java

java,swing,nullpointerexception,jbutton,actionlistener

public static void main(String[] args) { new Interface(); } public Interface2() { // .. It is likely that the main method of the Interface2 class should not be creating an instance of Interface!...

How to use ActionListener in ComboBox

java,button,actionlistener

You are reassiging the playerStatPane variable, but that does not mean the old value is replaced in panes. Try this: public void actionPerformed(ActionEvent e) { panes.remove(playerStatPane); JComboBox cb = (JComboBox) e.getSource(); String name = (String) cb.getSelectedItem(); if (name.equals("Chip")) { playerStatPane = createStats(p1); } else if (name.equals("Dale")) { playerStatPane = createStats(p2);...

Add new label and textfield on button click Java

java,swing,jbutton,actionlistener,jlabel

You have a few choices: You could... Create a ActionListener for each button, this can be done using a outer, inner or anonymous class, this means that you provide a self contained unit of work for each button which is related to only that button. You could also take advantage...

How is action on JButton being invoked in this code?

java,swing,jbutton,actionlistener,windowlistener

When you click on ok button, your actionPerformed method will get called as you registered callback on ok button as okButton.addActionListener(new CustomActionListener()); When you close your awing window from top right 'X' button, your program will exit with a return code of 0 and that's what your window listener...

JButton listener not firing

java,swing,button,actionlistener

You are having two instances of LoginDialog class. One you are creating in your controller and the other one is in your LoginDialog#showLoginDialog() method. Let's list them: 1st instance - In the controller class named `loginDialog` 2nd instance - In the `LoginDialog` class named `ld` Here ld is an object...