jbutton

Sharing state between JButtons

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...

Getting an explicitly set foreground color for a JButton

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...

about rotating text3d

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 ...

Showing/hiding a JPopupMenu from a JButton; FocusListener not working?

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...

Having a different action for each button dynamically created in a loop

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...

can I rotate the button or label into vertically in java?

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? ...

How do you simulate a click on a JTextField? Equivalent of JButton doClick()?

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. ...

Changing JButton background colour temporarily?

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...

Using MigLayout, why is a JButton following a JTable unresponsive and how to fix this?

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...

What is the correct way to set size of elements of GUI?

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...

Hide jButton in Netbeans

Hi, Is there a way to hide a jButton in Netbeans? (similar to button.visible = false in VS) ...

Why setPreferredSize does not change the size of the button?

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...

Java swing hold buttons

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 ...

Java Package - To create a button and import one when needed.

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...

I'm tired of JButtons, how can I make a nicer GUI in java ?

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...

Setting Background of a Jbutton

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...

Problem with button addition when double clicking a command label

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...

Why I see only part of the image in the button?

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....

add JButton into frame with JTable

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 ...

Make a JButton exactly the same size of its Text

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 ...