jbutton

JButtons fail to appear in the JFrame

Hi, I have code that displays a menu and 4 JButtons in a JFrame. I tested the code last night and everything was working fine. Now the JButtons do not appear in the JFrame today in the morning. I tried doing in Eclipse and still I got the same result. The output I am getting : My code: import java.awt.Color; import javax.swing.J...

Why do the JButton in my dialog look weird

I'm fairly new to Java Swing/AWT et al and hence the question. I have a simple dialog with some text and a couple JButton. I am using the GridbagLayout for this dialog. But when I look at the dialog, the JButtons are kind of having a weird shape and I cannot seem to right justify the text either. Is this a limitation of the Layout I ...

JButton updating its own isEnabled value

I'm trying to create a sub-class of the JButton component that will enable or disable itself based on a condition (which looks like below) public interface Condition { public static final Condition TRUE = new Condition() { public boolean test() { ...

Java drawOval after random time when user pressed Jbutton

So when the user presses my JButton, it picks a random time, and after that time, it will draw a oval to the screen. However, with what I have now, it draws the oval right after the button is pressed. I want it to appear after a random time. public void actionPerformed(ActionEvent e) { if (e.getSource() == startButton) { ...

jButtons resize on runtime

I want to resize the JButton at runtime by clicking on its border and draging it. Can anyone explain me how to do it with a sample code. public void mouseDragged(MouseEvent E) { Point point= E.getPoint(); //JButton get = floor_plan.dynamicButtons.get(E.getComponent()); JButton get=(JButton) E.getComponent(); int height = get.getHeight(...

Resizing JButtons and other components according to text

How do you resize a JButton at runtime so it adapts to the text given by setSize? I've done some searching and this is the code I've come up with so far. Could this be turned into a utility method? FontMetrics metrics = getFontMetrics( font ); int width = metrics.stringWidth( string ); P.S: No layout manager is being used. ...

actionlistener returning a nullexception on jbutton

I have an action listener set up on my main jframe menu for the buttons listed on it, and they work fine, bringing up other jframes as needed. The problem is when a person clicks the buttons on the jframes brought up I get a nullexception after a jbutton is clicked on that submenu jframe. Example code: public class main extends JFrame...

Java - Adding JButton to JApplet

I am trying to add a JButton Array to my GridLayout but it seems not to be working. Probably a rookie mistake -- what am I doing wrong? import java.awt.*; import java.applet.Applet; import javax.swing.*; public class Grid extends JApplet { public JButton[] inv; public void init() { setLayout(new GridLayout(4,5)); ...

JTable: Buttons in Custom Panel in Cell

Hello everyone, I want to be able to have a JPanel in a cell with a JButton that does some work when clicked. I looked for howtos about Cell Editors, but all examples talk about replacing the cell with another component (e.g. replace an int with a JTextField etc.) My situation is a little different: I have the following ADT class My...

Swing make a JButton not focussable

I want to make a Java swing button 'not-focussable'. The button should not receive focus at all, but should be able to receive mouse clicks. I thought the following options, but these either dont solve my problem completely, or dont seem elegant. Are there any other/better/suggested options? Move the focus to the next component immed...

How to put a JButton inside a JTextField (Java)?

I would like to have a JButton (with a folder icon image) inside a JTextField, like over on the far right of the JTextField, so that when clicked, the button opens up a JFileChooser, and when a file is selected, the path to the file appears inside the JTextField. I have made this code, but nothing shows up. public class TextFieldChoose...

Why will BoxLayout not allow me to change the width of a JButton but let me change the height?

I'm trying to get the Layout of a JDialog of mine to fit a particular look that a program in which I'm porting to Java has, I've used several LayoutManagers before with great success yet for some reason I cannot seem to get this working at all. My goal is to have the Right (East) side of the JDialog contain a "Find Next" and "Cancel" but...

JButton does not work with setAccessibleName and NVDA

I am using the following code and would like to hear NVDA and JAWS announce my button when I roll over it. The JFrame name and title bar components are announced, but that is all. Can someone help? import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JFrame; //import javax.accessibility.*; public class JFrameExampl...

JButtons dont get the Correct Size and Location

Hello I have a Problem with some Buttons I would like to create a simple GUI with JButtons but when I start the App the Buttons Positions and Size changes every Time when i start the App. I use this Code: usr_in.setSize(120,40); usr_in.setLocation(10,40); usr_in is a JButton Created Like this: JButton usr_ro = new JButton("Use...

How can I remove the gap when using a JButton as a ComboBoxEditor in the Windows L&F?

I'm trying to use a JButton as an editor within a JComboBox. On Mac OS X this looks fine, but on Windows using the system look and feel, there is an ugly gap left between the JButton editor and the combo button itself: This is the test code used to produce the dialog: import java.awt.*; import java.awt.event.*; import javax.swing.*;...

How to disable JSplitPane arrow button

Hi, How do I disable(grey-out) the arrow button on the JSplitPane. I do know how to get the button from BasicSplitPaneDivider like this: final int UP_ARROW = 0; final BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI(); final BasicSplitPaneDivider divider = ui.getDivider(); final JButton upArrowButton = (JButton) divider.getComp...

How do I save preference user settings in Java?

For example, I have a window with a preference button. I want to make it so that when user press the preference button and checks his/her appropriate options and press ok, it saves the preference, then when user presses run on the main window, it runs accordingly to preference the user changed on the preference window. Thank you in adva...

Painting a custom JButton and a text line

Hi everyone! I'm designing an optimization system for public transport in a big city. So I have a map with some points on it, but don't care about it) All I need is: my own JButton, which looks like a color-filled circle and a small text tag near it. I got some problems while overriding the paintComponent() method.. the round button is p...