Can't change LaF JMenu "buttons" - java

As I'm modifying an existing Look and Feel, I also want to change how the "buttons" of a PopUpMenu behave. Right now it behaves like this, when I hover my mouse over it. As you can see it behaves very "3D":
And I want to let it behave like the buttons I made below them:
I've looked trough alot of documentation of Java Swing but I can't seem to find it. So if someone knows, please help me out. I have tried to change every property I could find.

The correct answer here is, as I found out, not everything can be managed by the LaF. Therefore, sometimes you have to get your hands dirty.
In this case I created my own CSTMButton, because in Swing one is also able to add buttons to a menubar. Now I can create it's own listener to generate the behaviour I want.

Related

Make a borderless JFrame

Any parameter to set A JFrame's border/frame thickness or existence and still keep the title bar intact? I want an almost borderless frame with a thin blue line like this one and not like the default border.
If JFrame isn't the way to go, what is a good way to achieve that? (preferably that is compatible with WindowBuilder but that's probably asking for too much).
A search barely yields any mention and related questions on SOF don't seem to have answers so I thought I'd try to get a good answer once and for all.
JFrame#setUndecorated
Disables or enables decorations for this frame.
This method can only be called while the frame is not displayable. To make this frame decorated, it must be opaque and have the default shape, otherwise the IllegalComponentStateException will be thrown. Refer to Window.setShape(java.awt.Shape), Window.setOpacity(float) and Window.setBackground(java.awt.Color) for details
Please, consult the available documentation
Please note, you will become responsible for providing the title bar yourself, should you want it
A search barely yields any mention and related questions on SOF don't seem to have answers
Google provides a number of promising hits
I ended up switching to NetBeans and learning some Photoshop basics which you'll need thanks to a comment by #MadProgrammer
writing your own look and feel delegate
and ended up exactly with what you mentioned #theProgrammer101
You can make a JButton, and when it is clicked, call System.exit(0) , which will terminate the program
You can create a similar button for minimize action as well as your own drop down menus that are totally custom made and you won't need to rely on the default JFrmae window in case that bothers you too (I found it horrid).
check out this link for a good NetBeans tutorial with an nice example of writing your own look and feel delegate and this link for a great tutorial on getting started with Photoshop which is critical to GUI creation.
Thought i'd round up some of my research for anyone else who's just getting into GUI's.

Adding 2 groups of JRadioButton to be corresponding the same

I am doing a simple GUI painting box program.
However, I have a problem with adding 2 similar separated groups to be corresponding in the same way.
I mean when I click the JRadioButtonMenuItem Line, then the JRadioButton Line below also has to be selected too. What should I do?
Do you need to see my code?, please let me know
Thank you so much.
P/s: it says I need 10 reputation to post image
Share the model between the two radio buttons:
JRadioButton radioButton = new JRadioButton("Line");
JRadioButtonMenuItem radioMenuItem = new JRadioButtonMenuItem("Line");
radioMenuItem.setModel( radioButton.getModel() );
Actually, you should share the Action as well between the two components. Read the section from the Swing tutorial on How to Use Actions for more information and examples.
The exact solution depends a lot on how your code is structured right now. I bet that the standard library has some functionality to accomplish what you want to do, but if you want to go ahead and implement it then you might as well (minimal time input and you learn something).
The most direct solution that comes to my mind is to encapsulate selecting a button in a method that will manipulate all sets of corresponding buttons. I am going to assume that you are using action listeners for the buttons right now, if not you could adapt the idea. In the action listener, you can detect the mouse click and perform some work as necessary. That work should include updating the other buttons appropriately too. You could even create a method that both action listeners call and updates all necessary sets of buttons.
It is also possible to use the same action listener on both sets of the buttons, but you'll need to know which selection the user wants to be active (likely an easy task).
My Java is pretty rusty, so I am not including any example code, but if anything is unclear or you think an example would help I can do so.
Hope at least something here helps you. Good luck!

How to edit the Scroll Bar

I have a JTable in a JScrollPane but I'd like to change the look of the ScrollBar to something a bit better looking; a 'custom design'. Maybe put an image that a user can drag instead of the default thick blue bar. Is this even possible?
The main thing I'd like to do is change the thickness of the bar. My application uses a small window and the ScrollBar looks too thick.
Any help will be much appreciated.
Edit:
Thanks for the responses so far. I just found this; answers my answer, in part: java scrollbar thickness
Unfortunately I cannot provide a sample at the current moment, but you should definitely look into this
The BasicScrollBarUI class allows you to modify different features of a typical JScrollBar, such as various different colors, sizes, and shadow effects. This should be what you are looking for. Basically the idea is that you are supposed to override the installDefaults method and just modify the protected fields to your liking.
But, if you want to get fancy, I would highly suggest looking into JavaFX due to the amount of customizability it supports, one being CSS styling (which should be very helpful to you).

JComboBox staying open

I have written a GUI which has many different JComboBoxes. All of them work as I would expect (I click on them, the popup appears, I click on my selection, and the popup closes).
All of them, that is, except for one.
I have looked at my code, and I am using this combo box in the same way as I am using others. I am sure that there is something that I am missing, but I do not know what.
I do not know where to start. What kind of thing should I look at in my code to figure this out? If you were to try to achieve this, what would you do, this info might help.
As a code sample, I have not done anything out of the ordinary:
JComboBox selectionBox = new JComboBox();
selectionBox.addItem(DEFAULT_SELECTION);
selectionBox.addItem("Option1");
selectionBox.addItem("Option2");
selectionBox.addActionListener(this);
Although I understand that it isn't always possible to give a lot of details, an exact answer just isn't possible without more exact information.
That said, I think the best course of action is to examine the code very carefully and make sure that an error cannot be found that could be causing the JComboBox to stay open.
As a LAST resort, you may be able to fix the problem by using JComboBox's hidePopup() method to manually close out of the JComboBox:
yourComboBox.hidePopup();
P.S. As for not knowing where to start ... if, in general, you're having trouble finding errors in your code, https://softwareengineering.stackexchange.com/ might be a good place for that sort of question.

Working in java image

I will explain my question clearly.
I need to zoom in/zoom out the world map.
When I click on the particular country in map, control should redirected to new page with respective the country.
I dont have any idea about this in java. Please explain the steps to acheive the above task.
As the question is quite general, here is a general answer: Zooming often means, that you want to display a certain percentage of somethin, and not the whole, where your size of the displayed will not change.
But in your case it seems more like a "find a mouse click in a polygon" thing. So you have to add a selection/click listener to whatever widgets you use (Swt? swing? ....?) where you change what your program renders.
It sounds like you may be trying to reinvent the wheel. Google etc have already solved this problem rather well. It might be better to incorporate an existing solution into your application. Have a look at GoogleEarth inside Java Swing.

Categories

Resources