I want to create two or more JButtons that share state, i.e. when the mouse button is pressed over either JButton, both are rendered as depressed (aka "armed"), or if they are checkboxes, both are checked/unchecked simultaneously etc.
To the user, it must appear as if both buttons were the same button, appearing in more than one place i...
I have a custom ButtonUI class that paints the button. Before drawing the text, the paint method checks whether the button has been set a custom color in order to use that instead of UIDefaults#get("Button.foreground").
if ((b.getForeground() != null)) {
colText = b.getForeground();
}
Having a look into the java.awt.Component clas...
Hi
as we know ,we can add one icon to the button
jButton1.setIcon(Icon c);
can we add a rotating image to the button?(text 3d)
if yes,please help me with a simple code.thanks
...
Hi everyone,
I needed a JButton with an attached dropdown style menu. So I took a JPopupMenu and attached it to the JButton in the way you can see in the code below. What it needs to do is this:
show the popup when clicked
hide it if clicked a second time
hide it if an item is selected in the popup
hide it if the user clicks somewher...
Hi, use this website a lot but first time posting.
My program creates a number of buttons depending on the number of records in a file.
E.g. 5 records, 5 buttons.
The buttons are being created but i'm having a problem with the action listener.
If add the action listener in the loop every button does the same thing; but if I add the act...
I want button in vertically, for that i can extend the height and shrink the width of that button. But the text of the lable of buttons are in the form of horizontal only. For that can i rotate the whole button vertically and is it possible?
...
I am working on a Java project and need to have a keypress simulate a click on a JTextField. What I'm looking for is the equivalent of the JButton doClick() method.
I am trying to have the keypress "enter" perform the exact same function as a click on the JTextField.
Not sure what other info to provide. Thanks in advance.
...
Hi,
I'm super new to Java, and in need of some help.
I'm making a little java desktop application where I basically have a grid of 4 JButtons ( 2 x 2 grid), and I need the background colour of individual JButtons to change, and after one second, change back to the original colour (the game I'm trying to make is like Simon, where you hav...
Hi everyone,
I am having a mind-boggling problem regarding the use of a JButton following a JTable with MigLayout. It is totally unresponsive unless I push it far enough past the JTable (then it can behave correctly).
I have tried running the code with both the MigLayout JAR of the version we use for end user products and with the very...
I am using swing to create my GUI. J have a JFrame containing one main JPanel which, in its turn contain several JPanels which, in their turn, contain buttons.
I would like to set certain sizes to mu buttons and JPanels. How does it work? Should I set sizes of my buttons and then the size of the JPanel and the JFrame will be set accordi...
Hi,
Is there a way to hide a jButton in Netbeans? (similar to button.visible = false in VS)
...
Here is the code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class TestGrid {
public static void main(String[] args) {
JFrame frame = new JFrame("Colored Trails");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel mainPanel = new JPanel();
mainPanel.setLayou...
Hi, I'm trying to create a subclass of JButton or AbstractButton that would call specified .actionPerformed as long as the mouse is held down on the button.
So far I was thinking of extending JButton, adding a mouse listener on creation (inside constructor) and calling actionPerformed while the mouse is down. So far i came up with that ...
This is more like a package/import test. We'll start with my base folder at .../javaf/test.java
My goal is to create subcategory and create a class with a button that I can import to test.java when I need a button. I feel like I've done it right, I know that the button doesn't do anything as of now, but I just want to make the whole thi...
So far I've only built "small" graphical applications, using swing and JComponents as I learned at school. Yet I can't bear ugly JButtons anymore. I've tried to play with the different JButton methods, like changing colors, putting icons etc. but I'm still not satisfied. How do you make a nicer GUI in java ?
I'm looking for not-too-hea...
Hello there,
I have 5 JButtons: b1, b2, b3, b4, b5.
By default, their color is gray.
When I click on any button, the background of that button changes to white.
When I click another button, I want that previous clicked button to change its background to gray, and this newly clicked button to change its background to white. Here is the c...
Hy,
I got an intersting problem which I stumbled upon. When I double-click a JLabel in a JSplitPane I want to add another jbutton in a JPanel, its a shorter way to make a dragg and drop. The problem is that the button doesn't appears only if i'll position the mouse on the area the button should appear. Why does it happens this way? Anyo...
I add an image to the button in the following way:
ImageIcon icon = new ImageIcon("images/col.jpg");
tmp = new JButton(icon);
My image is a red sphere but in my button I see only read color. I assume that I see just a small part of the sphere. How can I see the whole image in the button?
ADDED
Yes, my icon is bigger than the button....
hello,
I would like to know how to put a button inside a frame that contain JTable inside. (The button should not be inside a cell, but after the table ends)
Here is the example code I wrote so far:
class SimpleTableExample extends JFrame
{
// Instance attributes used in this example
...
Is it possible to make a JButton take exactly the size of its text? Since by default, a JButton will have a small amount of padding (both horizontal and vertical) around its text. I would like to remove that padding.
thx
...