jbutton

Is it possible to put text on top of a image in a button?

I have .jpg images in my buttons. I also would like to put some text on top of the images. I use the following syntax for that: JButton btn = new JButton(label,icon); But I do not see text in the buttons (only image). What am I doing wrong? ...

Why does my JButton look differently of different computers?

I use JButtons in my application. They need to have different colors. First I used that btn.setBackground(col);. It works on my computer and on another computer my button just gray (not red, as it's supposed to be). Trying to solve this problem I decided to use images. I do it in the following way: tmp = new JButton(newIcon); Again, it...

JButton keyboard shortcuts

Hello, I have two JButtons and I would like to allow them to be used by the Arrow keys whenever the JFrame is in focus, Can anyone point me in the right direction about this? Thanks ~ Kyle ...

How can I shift html-text in the JButton to the left?

I use HTML to put text into a JButton. In this way I can play with colors and text size. What I do not like is the distance from the left border of the button and the text (this separation is too large). Is there a way to decrease this distance? I think it should be some parameter in the style of the HTML code. Sample of the code: JBut...

using JInternalFrame and some JButton

hi can we use a JInternalFame with a button into the main fram (by JDesktopPane of corz), the button that open up the JInternalFame ? how? thks ...

Remove JButton padding in MigLayout

I have a small "popup" like this: But I don't want the padding around the button, I want it to be as small as it can be with the supplied text. btn.setMargin(new Insets(1, 1, 1, 1)); panel.add(lbl, "wrap"); panel.add(btn); frame.pack(); frame.setVisible(true); At least this doesn't work... Can this be achieved on MigLayout or shoul...

resizing a ImageIcon in a JButton

I am creating a JButton which includes a specific ImageIcon. The main issue is that the original icon size is much bigger than the button size. As result when the button is displayed, only part of the icon can be seen. What is the method that "resize" an ImageIcon i n order to make it fit inside a JButton? ...

Bad event on java panel

Hi I have a java panel with 4 buttons. When I click on of these buttons, a new frame appears and the first is hidden with setVisibile(false). On that new window, I have another button, but when i click it, I got the event corresponding to the fourth button of the first window. Clicking the button again does the trick, but of course t...

Faulty JButton event listener

I have created in my Java Swing application a main window with a JButton. I have added to this button an event listener class (implementing the ActionListener interface) which, every time the button is clicked, launches a "pop-up" window. The method works fine when the button is clicked, except when the button is clicked for the first t...

Java/Swing: low-profile button height?

I would like to reduce the vertical size of a JButton. The following code works fine for K > 1 but I can't seem to reduce the size. Any suggestions? JButton button = /* ... get button here ... */ Dimension d = button.getPreferredSize(); d.setSize(d.getWidth(), d.getHeight()*K); button.setPreferredSize(d); edit: I'm using JavaBuilders ...

Draw a JButton to look like a JLabel (or at least without the button edge?)

I've got a JButton that for various reasons I want to act like a button, but look like a JLabel. It doesn't actually have to be a JLabel under the hood, I just don't want the raised button edge to show up. Is there an easy way to turn off the "button look" for JButtons but keep all the button functionality? I could build some kind of ...

How to remove gap between controls in JToolBar?

How to remove gap between controls in JToolBar? I want to have no free space between controls in JToolBar. EDIT: I was wrong. There is no free space. The problem is caused by JButton (situated in JToolBar) with icon only. It has some extra margins around the icon. How to remove them? ...

How to close a JFrame based window with a JButton click event

I am new to the whole Java Swing/AWT dialogs (which explains how amateurish this dialog below looks like, any help in arranging it better is welcome :) and I am struggling to close this popUp window when any of the two JButtons are clicked. I have already tried options like frame.dispose(), frame.setVisible(false) and even SwingUtilitie...

Simple JFrame dialog displaying JButton

First off, I am real new to Java Swing/AWT and not intricately familiar with the workings of JFrame, JPanel & JButton. I want to just display a simple PopUp dialog with a some text and a couple JButtons and it should exit when any of the two buttons are clicked. I have most of that logic in this class, however I'm still struggling to mak...

Why is my simple JFrame displaying weird?

I am a newbie at Java Swing/AWT and I have this code following working for a simple PopUp dialog which closes on any of the JButtons beind clicked, but displays real wonky. Does anybody have suggestions on what and how to fix? import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java....

Stop JButton repainting on mouse over?

I have created a custom JButton class for representing spaces on a monopoly board. The game is multiplayer so a lot of the information needed to draw the button is held on the server (accessed via RMI). My problem is that when I mouse over the button it automatically seems to call repaint() (and draws a border). This makes the program ...

JButton action Listener

Hey there, I'm searching for a Key Listener which always activates himself when the mouse is pressed down... for example if I keep pressing the button it will always write something on the console and stops writing that when I releas the mouse button. ...

How to place JButtons at a certain coordinate in a JFrame

Hi, I want to know how to place JButtons at a particular coordinate in the JFrame. All day I have seen layouts. This does not suit my purpose. I would prefer something like setBounds. Rumour has it that it does not work but setLocation does. I tried it but, the program disregards the setLocation line and sets it to a Layout. CODE i...

Swing JButton don't change background color onclick

I want the button on click it never change the background color, by default the color will change to light blue grey color. So this is my code JButton b = new JButton(); b.setBackground(SystemColor.control); I want the button when on click it will never change the background color. ...

How to place a JButton at a desired location in a JFrame using java

Hey, I want to put a Jbutton on a particular coordinate in a JFrame. I put setBounds for the JPanel (which I placed on the JFrame) and also setBounds for the JButton. However, they dont seem to function as expected. My Output: My Code: import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing...