I have created a small Java application which has a JList. The JList uses a custom cell renderer I named SmartCellRenderer. The SmartCellRenderer extends JPanel and implements the ListCellRenderer. I have added two buttons on the right side inside the JPanel of the SmartCellRenderer, since I want to buttons for each list item, and I have added mouse/action listeners for both buttons. However, they don't respond. It seems that the JList property overcomes the buttons underneath it. So the buttons never really get clicked because before that happens the JList item is being selected beforehand. I've tried everything. I've put listeners in the Main class, called Editor, which has the JList and also have listeners in the SmartCellRenderer itself and none of them get invoked.
I also tried a manual solution. Every time the event handler for the JList was invoked (this is the handler for the JList itself and not the buttons), I sent the mouse event object to the SmartCellRenderer to manually check if the point the click happened was on one of the buttons in order to handle it.
I used:
// Inside SmartCellRenderer.java
// e is the mouse event object being passed from the Editor whenever
System.out.println("Recoqnizedt, but not a button click...");
//return;
} else {
System.out.println("Recognizedt, IT IS A MOUSE CLICK, PROCESSING...");
}
System.out.println("VALUEomp.toString());
What I realized is that not only this still doesn't work (it never realizes the component as a JButton) it also throws an exception for the last line saying comp is null. Meaning with the passed x,y position the getComponent() returns a null which happens when the coordinates passed to it are outside the range of the Panel. Which is a whole other problem?
I have yet to find an example on the web, using Google, that demonstrated using buttons inside a JList.
My Machines with Classic Outlook 365, have a banner on top Next Time Outlook is opened, will be autoly switched to NEW Outlook, not sure if i should try to prevent that or just get used to new Outlook at this point
Probably gonna try to prevent that now that i read that privacy notice
Yeah, no. I won't be "upgrading" to the "mandatory" Windows 11 until all the bugs with DirectX and Hibernate are sorted out. Until then ASUS and Microsoft can both stuff it where the sun don't shine.
Tech demos are a declaration of desire, an horizon for what they pretend to put on those boxes call consoles (i still laugh at the poor implementation of Hairworks in W3 when you compare it with the demos)...being made on UE5 doesn't give me any confidence considering how poorly it runs in those things, and CDPR is not a marvel in that aspect neither.
And about the game, so far is non existent besides the cinematic trailer. If from the get go they have to justify the whys for the protagonist, you start your narrative with the left foot.
Seen a 5090 for just over $3,000 at Best Buy just a couple days ago.
It wasn't the sticker price that made me laugh... it's knowing that, for now... that kind of investment that includes drivers that don't work, is a headache no one should have to shell out for.
But.. it's not the first time Nvidia has choked on crappy drivers, won't be the last.. so, if you spent a pretty penny on the next gen, hang in there... sure they'll get it right some day here soon.
Question
SigmaX
Hi everyone,
I have created a small Java application which has a JList. The JList uses a custom cell renderer I named SmartCellRenderer. The SmartCellRenderer extends JPanel and implements the ListCellRenderer. I have added two buttons on the right side inside the JPanel of the SmartCellRenderer, since I want to buttons for each list item, and I have added mouse/action listeners for both buttons. However, they don't respond. It seems that the JList property overcomes the buttons underneath it. So the buttons never really get clicked because before that happens the JList item is being selected beforehand. I've tried everything. I've put listeners in the Main class, called Editor, which has the JList and also have listeners in the SmartCellRenderer itself and none of them get invoked.
I also tried a manual solution. Every time the event handler for the JList was invoked (this is the handler for the JList itself and not the buttons), I sent the mouse event object to the SmartCellRenderer to manually check if the point the click happened was on one of the buttons in order to handle it.
I used:
// Inside SmartCellRenderer.java
// e is the mouse event object being passed from the Editor whenever
// a JList item is selected or clicked on
Component comp = this.getComponent (e.getX(), e.getY())
if(!(comp instanceof JButton)) {
System.out.println("Recoqnizedt, but not a button click...");
//return;
} else {
System.out.println("Recognizedt, IT IS A MOUSE CLICK, PROCESSING...");
}
System.out.println("VALUEomp.toString());
What I realized is that not only this still doesn't work (it never realizes the component as a JButton) it also throws an exception for the last line saying comp is null. Meaning with the passed x,y position the getComponent() returns a null which happens when the coordinates passed to it are outside the range of the Panel. Which is a whole other problem?
I have yet to find an example on the web, using Google, that demonstrated using buttons inside a JList.
Can anyone help me with this. Thanks.
Link to comment
https://www.neowin.net/forum/topic/249343-button-event-handler-in-a-jlist-please-help/Share on other sites
3 answers to this question
Recommended Posts