Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I wish to create a button exactly same as this (from iOS5).
You will have two images, for ON and for OFF.
Whenever you click the button, you will switch images with button.setImage(..).
Swing constraints:
Button will still be rectangular, even though the image is oval
Animation possible, but quite hard AFAIK. From the way you asked your question, I think it will take you a while to study swing more
In swing, there is JToggleButton which can have two status. However, if you want the button of the same shape and the same visual effect, you should implement it.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a problem with my project. I'm making a tool for numerical methods (a lesson in college). I have done nearly all of the project but I have a problem with my design.
When I resize it before making anything it resizes well but, if I set the size of the matrix after the matrice processes the panel isn't resizing.
The code works well if the rank is <=5, but the bigger matrices cause that problem.
I'm using window builder and the code is messy but I'll be glad if you try to help me.
Thanks for your helps!
Some of things that I noticed in your code.
Don't use null layout at all and avoid setBounds() method
Always hand over it to Layout manager to set the position and size the components.
Use ActionListener for JButton instead of MouseListener if you want to capture click event only.
Note: I can't run your code on my system due to character encoding issue. You have used some character other than English in your code.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
To set the default button to suppose jButton4 the following code has to be used: this.getRootPane().setDefaultButton(jButton4); But where to add this?
What all I tried:
I tried to add it in main function but it gave me an error, I tried to put it inside the button action performed block but it did not work, I tried to put it just before the main function it gave me an error.
Question: So where do I put this line of code so it works? I am using Netbeans GUI to make the program.
You could add this line everywhere you want to set the default button (a button click, where you create your UI etc.).
I think a nice place is where you create your UI elements.
In your case it would be, just after initComponents();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am asked to create a program as following..
"create random polygons, the point
when you press the mouse button is considered like a nail in the polygon. You can drag the polygon
with the mouse and place it somewhere on the wall. When you release the mouse button,
the polygon rotates around the nail in order to simulate the pulling of the gravity
You are not allowed to use methods from java (like AffineTransform). "
so far I managed to create random polygons, add a "nail", and drag the shapem but I can't seem to find a way to rotate it , can I -sort of- Transform it ?
One alternative to using an AffineTransform is to use geometry to calculate the new polygon.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to do my own program and what the basis of what I want is to use some sort of slider to take characters to different buildings. I essentially have a one long vertical road with my bus (which is what the slider will be). I know the general icon for a JSlider is a small pentagon that can be dragged to different values. I was just wondering, is there a way to change that pentagon icon into something of my choice?
You'll need to extend the BasicSliderUI and override paintThumb() to render the desired Shape. This example renders a triangle using drawLine().
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I created the Tab panel which is having 3 tabs, and in each tab I'm displaying chart.
My problem is I want to use arrow key to move a chart back and forth.
But when I pressed arrow it switches the tab.
How I can remove this default behavior of Arrow key of swiching tabs?
You have to unregister keybinding.
For example:
tabComponent.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("LEFT"), "none");
tabComponent.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("RIGHT"), "none");
You may want to take a look at this How to use KeyBindings.