You are not logged in.

#1 2017-02-16 06:20:10

dcbdbis
Member
From: Aurora, Colorado
Registered: 2004-09-10
Posts: 247

[SOLVED] Java Event Handlers are not Firing

Good Evening Fellow Archers,

Here is my config:

Product Version: NetBeans IDE 8.2 (Build 201609300101)
Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 1
Java: 1.8.0_121; OpenJDK 64-Bit Server VM 25.121-b13
Runtime: OpenJDK Runtime Environment 1.8.0_121-b13
System: Linux version 4.9.8-1-ARCH running on amd64; UTF-8; en_US (nb)

pacman -Q reports:
jdk8-openjdk 8.u121-1
jre8-openjdk 8.u121-1
jre8-openjdk-headless 8.u121-1
openjdk8-doc 8.u121-1
java-environment-common 2-2
java-runtime-common 2-2
netbeans 8.2-1

//---------------------------------

I must admit, I am a C/C++ guy. I am not a fan of Java, but have done a couple of apps in it when I needed cross-platform functionality. I have one more need for Java at the moment, and the event handlers are not firing.

These programs (NetBeans and the associated JDK's) were installed from pacman. They are not foreign packages that I downloaded. And yes, "pacman -Syu" shows my system fully up to date.

The issue is that the swing devices that I have placed on my GUI, are not firing their event handlers. The debugger is working and I get breakpoints that function as expected elsewhere....Unless those breakpoints are set in event handlers. After a lot of digging, it has become apparent to me that the event handlers themselves for the swing widgets are simply not firing. I don't know if this is a JDK 8* issue or a NetBeans issue. If I get no replies by the weekend, I will remove the java 8 stuff, and go with the JDK 7 stuff. But that is a blind stab in the dark as far as I am concernedt.

I come from Code::Blocks, wxWidgets, using C/C++ background. I have done C/C++ for 35 years now. But in Java, which is not my strength, I have no idea where to start looking to determine why the event handlers aren't firing. I don't know if I need to start looking into the installed JDK's, or the NetBeans environment - and if so - where?

If this was a wxWidgets issue, I would look to determine if I had compiled the wxWidgets suite correctly. But with Java/NetBeans, all the swing widgets come down the wire with it so I do not know where to look.

I have followed the wiki in NetBeans to ensure that my project, and my environment were setup correctly and using/pointing to the correct JDK. Beyond that - I have no clue where to look next to determine the problem. I have also nuked the .netbeans folder and started over. No change with the issue.

I would really appreciate suggestions.


Sincerely and respectfully,

Dave

Edits: Spelling and grammar

Last edited by dcbdbis (2017-02-17 02:14:10)

Offline

#2 2017-02-16 08:56:28

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,728

Re: [SOLVED] Java Event Handlers are not Firing

Would it be possible to share your code, or at least the excerpts of how you try to use a handler? I don't mean to sound condescending, but this does sound more like an issue in your code than something that would be fixed by trying to shuffle your setup and libraries around (there haven't been any really relevant changes to Swing components between 1.7 and 1.8 anyway) one thing that might have a very slight chance of being an issue with your environment, would be that you run e.g. Gnome on Wayland as opposed to Xorg and there being a compatibility problem in Xwayland.

Last edited by V1del (2017-02-16 08:59:19)

Offline

#3 2017-02-16 16:05:01

dcbdbis
Member
From: Aurora, Colorado
Registered: 2004-09-10
Posts: 247

Re: [SOLVED] Java Event Handlers are not Firing

Thank you for the reply.

The code here is simple. It is the default event handler, with just "placeholder" code in it. It does nothing as I can't get the handler to fire, so there is no operational code in it at the moment.

I set the breakpoint on the "int a = 0;" line, then debug the program. It never fires. I had operational code in this handler, until it became apparent that the event handler wasn't working properly.

 private void jSpinner1MouseClicked(java.awt.event.MouseEvent evt) {                                       
  int a = 0;    // TODO add your handling code here:
  }   

Last edited by dcbdbis (2017-02-16 16:06:13)

Offline

#4 2017-02-16 22:34:02

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,728

Re: [SOLVED] Java Event Handlers are not Firing

That is an evil one in particular. The JSpinner handles mouseclick events internally and they aren't propagated to your handler. Use ChangeListener on the JSpinner e.g.

public class MainProgram implements ChangeListener {

       public static void main(String[] args)  {
		
		MainProgram mainProgram = new MainProgram(); 
	
	}


	public MainProgram() {
		JFrame panel = new JFrame("Test");
		panel.setSize(100, 100);
		JSpinner spinner = new JSpinner();
		spinner.addChangeListener(this);
		panel.add(spinner);
		
		panel.setVisible(true);
	}

	@Override
	public void stateChanged(ChangeEvent e) {
		System.out.println("Hey it works!");
		
	}
}

If you really want to have mouse click events you could get the child components of the JSpinner  and add the mouse click event to the corresponding element.

Last edited by V1del (2017-02-16 23:18:30)

Offline

#5 2017-02-17 02:21:48

dcbdbis
Member
From: Aurora, Colorado
Registered: 2004-09-10
Posts: 247

Re: [SOLVED] Java Event Handlers are not Firing

Thank you for the reply.

Wow. Propagated event handlers showing up on the IDE that don't work out of the box. That is indeed truly evil. No wonder I was pulling my hair out.

Evil in the sense that you have to redirect and create a custom listener for something that is indicated at the IDE level that it has functional event handlers available.

I understand the code you provided.

Thank You for your Java expertise too, I do appreciate it. I would have never gone down this path on my own.


Dave

Offline

Board footer

Powered by FluxBB