swing

Java JTextArea - Adding a newline

So I'm stumped. I, for some reason, seem to remember that Java does weird things when you try to add new lines to stuff... so I think that may be the problem here. This code is not working how you'd expect it to: public void displayText(KeyEvent k){ txt = inputArea.getText(); outputArea.setText(txt); if(k.getKeyCode() == 1...

setLookAndFeel and NullPointerException

Hi! Has anyone ever tried to change swing's look and feel? This code, taken from an example, simply yields a null pointer exception, and I wonder what might be wrong: (javax.swing.UIManager/setLookAndFeel (javax.swing.UIManager/getSystemLookAndFeelClassName)) Thanks! ...

How to resolve swing listener memory leaks?

Background So I read that often memory leaks within Swing applications originate from the use of various listeners (mouse, key, focus, etc). Essentially, you register an object as a listener and forget to deregister the object, the notifier ends up holding onto the reference of the object, leaking a bit of memory. I knew our applicatio...

JDialog with minimize button

Is it possible to have a minimize and maximize button for a non-modal(modal=false) JDialog.I know JFrame is the ideal solution for this but this change has to be made in an existing code and its little difficult to change from JDialog to JFrame. ...

Dragging A Circle on a JFrame

I am trying to have a circle appear on the screen, then when the user clicks INSIDE the circle, enable the ability for them to drag the circle where the mouse goes while it is being pressed. This is the code i have so far, the drag works, but it is allowing the user to drag without them pressing the inside of the circle, just when anywh...

javax.swing.grouplayout not exist in jdk 1.5

I developed a java application with netbeans. It used jdk 1.6. It works fine. But now the requirement is I need to build the jar for the application from the .java files in another machine without netbeans and where jdk 1.5 is used. I cannot upgrade that machine to jdk 1.6. Is there any way I could make my java files compile and work ...

Swing question / JTree / custom tree model

Hello, I'm having a problem and hope, someone knows what's going wrong and why and is able to give me the explanation of what I'm missing out right now to make that thing work as suggested. I have a JTree which is build upon a custom TreeModel ("WRTreeModel", see below). The data structure this model shall be used for is build of an ro...

Suppressing Swing Visibility

Hello, I've been given a bunch of messy code and a short time limit (no surprises there) to write some tests for it. I have written tests! They are good tests. Unfortunately, instantiating some of the project's components causes Swing GUI elements to be constructed and set visible too. I don't want this to happen for obvious reasons, s...

Java Swing: change background color on mouse over

Hi, I've implemented a simple mouse listener where the background color changes whenever the mouse enters the component (a JPanel), and it reverts back whenever the mouse leaves. This has some problems: Sometimes the mouse moves so quick that the mouseExit event is not fired If my component has childs, when the mouse moves to the chil...

Is there a convenient way to use a spinner as an editor in a Swing JTable?

I deal with numeric data that is often edited up or down by 0.01*Value_of_variable, so a spinner looks like a good choice compared to a usual text cell. I've looked at DefaultCellEditor but it will only take text fields, combo boxes or check boxes. Is there a convenient way to use a spinner? ...

Why does repaint(long) repaint immediately?

According to the Javadoc, JComponent.repaint(long) is supposed to schedule a repaint() sometime in the future. When I try using it it always triggers an immediate repaint. What am I doing wrong? import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent;...

Java Swing JToolBar

I have created JToolBar (Java Swing). I have set a Background image on frame which contains JToolBar. I want my JToolBar to be transparent so that the image kept on frame should be visible. I am using setOpaque(false) but it is not having any effect on my toolbar.. Has anyone delt with this before? My Code is as follows import javax.swi...

Fire mouse event on underlying components

I'm looking for a way to pass mouse events to components covered by other components. To illustrate what I mean, here's a sample code. It contains two JLabels, one is twice smaller and entirely covered with a bigger label. If you mouse over the labels, only the bigger one fires mouseEntered event however. import java.awt.Color; import j...

Java Swing Fade Out Background

I have a Swing application and I'm trying to fade out the main application and show a window saying an operation is in progress (this is for long running operations that may need to block the UI). Is there an elegant way to do this in Swing (mainly the fading out the background) or maybe some swing library to help with this (maybe from s...

Java Swing JButton

I want to create button with custome look and feel. I have got different images to be set as background of button for normal, mouse over, mouse click, button disabled etc. I have created my own class, extending javax.swing.JButton and overrides paintComponent method. How can i change my button background for all the above given states. ...

how can I use font style for my whole frames or dialogs???

I have a main frame which has a menu bar and let user to change the font of all the texts in my program.I can just set the font for the main frame but how can i set that change for all my frames and dialogs??? ...

Java Swing JButton

I have created customized Button. For that i have overrided paintComponenet method. How can I set Button Text on such button? I tried doing it using drawString method. But which x,y values should i give? (g.drawString("button text",x,y)). Please till me if anyone has handled this. @Override public void paintComponent(Graphics g) { s...

JFileChooser.showSaveDialog(…) - preserve suggested file name after changing directory

There are already some questions about how to set a default file name for a JFileChooser control. I'm having a few problems with preserving that default filename when switching directories. Right now, when I do that, the original filename I supplied get over overwritten by the path of the new directory itself. Is there anything can be ...

Standards for using inner classes for GUI?

Hi, I'm wondering about the standard practice with inner classes (in Java but I suppose it applies to all OO languages). So I have a JFrame subclass ControllerWindow that contains a JPanel subclass MapPanel which I draw onto (so it needs to overwrite paintComponent method) and which needs to implement a mouse listener. My current solutio...

Adding a Web Browser in a JFrame/JPanel/JComponent in Java

I'm doing a Java application that requires to use a web browser inside the application. I have seen some applications doing this, such as RSS readers when clicking in a feed in the left panel and opening the link in a right panel in the same application, and I would like to implement something similar. Is it possible to do this in java...