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.
I have tried that registry 'trick' from that video already. It doesn't work at all in Win11 for me
Yes it's a 3rd party app... that I am only using because of Microsoft breaking user customization in Windows 11.
So yes... the is a Windows 11 issue. As of now to me, Microsoft has made a huge mistake with this in Windows 11.
The current font option in Windows 11 are terrible. They are just missing. People that want to use their own computer the way they want to, they need to avoid 11.
It's been an age since I did desktop support, but here goes:
You have an issue with Windows 11, which is fair. You are using a freeware 3rd party app to make modifications to the default Windows 11. Since an update, this 3rd party application no longer plays nice with Windows 11. And this is somehow Windows 11's fault?
Sorry, not buying that this is a Windows 11 problem... it's a customization issue that has just appeared, but standard 3rd party support.
Clearly you're upset. You can't make Windows do anything, just like you can't make MacOS run Explorer or Linux run Nintendo games natively. And I know people are going to say "sure, it's possible..." but those aren't defining elements of the OS. You can't have animated backgrounds in Windows 11 natively -- so it's trash amirite???
I did quick searches about changing the default fonts and there are ways to do it, and clearly 3rd party freeware apps can do it (basically my guess is they're making registry changes on your behalf) and clearly they're having issue. You can make your computer do a lot of things, but sometimes you get what you pay for.
Did a quick search and don't see an easy option in Windows 10 either. Some of these links - ironically - are for Windows 10. They still apply.
Here's a video tutorial of how it can be done without a 3rd party:
Same reference here with a bit more detail: https://www.howtogeek.com/716407/how-to-change-the-default-system-font-on-windows-10/
Once the font is chosen, the size can be changed via personalization from my understanding.
Hope this helps.
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