swing

Problem with keylistener.

hi i'm using swing and in my main frame(JFrame) i want that when ever user press + key one window lets say test should appear. my key listener works fine if i don't call the show method of the newly added JInternalFrame but when i call the show method of my JInternalFrame the KeyListener stops listening any more. i've tried a lot to so...

how to center image when Jpanel resized

How can i center image when i resize jpanel in swing ? my initial state of the Jpanel that its fits the size of the image ( with pack() ) but now when i resize the Jpanel with my mouse i will like to maintain the image in the center of the Jpanel relative to the Jpanel size ...

Understand Command Pattern in Swing

Hi I can see how Swing uses Decorator and Observer pattern. Observer: Every component(fx JButton) is a subject which can add observers(ActionListeners). When someone pushes a button it notifies all its ActionListeners by calling their actionPerformed(ActionEvent e). But how about Command Pattern? When I am making classes that implemen...

How can I draw rulers in a JPanel?

I have a JPanel that contains an image. I want to draw rulers on the JPanel's borders. How can it be done or where should I look for some hints? ...

Synchronizing JTable and JTree

Is there a way for a JTable and a JTree to share the same model, so that any change in that underlying model is reflected immediately in both components ? ...

Zero-padding a spinner in Java

How do you add zero padding to a JSpinner? Since the spinner creates the JFormattedTextField itself, I can't just pass the format into the JFormattedTextField constructor. Isn't there a way to set the formatting on an existing JFormattedTextField? What I want: value = 37, editor = "0037" UPDATE: I have tried this as suggested: JSpin...

Controling the size of components in Swing when their frame is resized

I have a simple form like this: Username: .......... Password: .......... When the form is re-sized, I would expect JTextField (illustrated by .........) to be re-sized horizontally to fit the new width but not vertically (the same height for JTextField). Do we have any way to control this? Thanks! ...

Swing: Can't get JButton to update - repaint() not working

I'm using Swing for the first time to create a simple GUI. It consists of a JFrame upon which I have placed a single JButton which, when clicked, calls some other code which takes approx. 3 seconds to return. Just before the call to this code, in actionPerformed(), I want to update the text on the button to inform the user that processi...

Unknown source of ClassCastException (in JTables)

I'm presently refactoring a JTable which displays a multitude of different types of data. The primary reason for this refactoring is that there a few ClassCastExceptions (the author/friend who wrote the code is off on hiatus), and I can't seem to find where these are originating from. Due to the large codebase, I'm at a loss as to where ...

Footer row in a JTable

What is the best way to put a footer row into a JTable? Does anyone have any sample code to do this? The only approach I've thought of so far is to put a special row into the table model that always get sorted to the bottom. Here is what I ended up with: JTable mainTable = new JTable(mainTableModel); JTable footerTable = new JTable(...

Converting Swing application to JavaFX

What are necessary steps for converting Swing application to JavaFX? It would be interesting to know also about best practices for performing such task (i.e. problems that can be encountered and resolutions). ...

Pick recently selected colors in java

I would like to add a color picker dialog to my app that remembers recently selected colors, so that it's easy to pick the exact same color as before, instead of getting several slight variations of a color. I've tried but I couldn't do this with the standarard JColorChooser. JColorChooser has a recent-color panel in some look&feels (mo...

GUI programming in Scala

I'm trying to learn Scala, and I'd like to learn by writing a simple swing app, but I'm unsure what GUI programing looks like in a functional world, and specifically when using Scala. Any pointers, or tutorials, or gotchas when coming from an OO/Java background would be really welcome. ...

Howto manage the game state in face of the EDT?

I'm developing a real time strategy game clone on the Java platform and I have some conceptional questions about where to put and how to manage the game state. The game uses Swing/Java2D as rendering. In the current development phase, no simulation and no AI is present and only the user is able to change the state of the game (for exampl...

JavaFX component that emulates JTable

I have a large dataset that needs to be displayed for users and looking for Swing's JTable like component in JavaFX. ...

Applet works, but swing components won't appear!

So I am creating this applet which I want to have full on swing components in it. I have looked at all the docs, I have made the applet, and I can get something to show up in it if I override the update(Graphics g) method, but simply adding components to the contentPane doesn't seem to be doing it! What am I doing wrong? import javax....

How can I add JMenuBars,JMenus and JMenuItems using IntelliJ's Swing GUI Designer?

I can't find the components specified in the title anywhere in IntelliJ's Palette. I notice that the form has a JMenuBar, but I don't see it, and I don't know how to access it. Is there any way of using these components visually? ...

Java Swing: Approach for dynamically appending text in text area, have scrollbar update

What is the general approach with Java swing to update a textarea with lines of text (say from a Thread) and then have the text caret flow to the bottom of the textarea as text is being added. Also update the scrollbar so that it is at the bottom. I was thinking that I would have a stringbuffer and append text to that and then set the ...

Why does JPasswordField.getPassword() create a String with the password in it?

Swing's JPasswordField has the getPassword() method that returns a char array. My understanding of this is that the array can be zeroed immediately after use so that you do not have sensitive things hanging around in memory for long. The old way to retrieve the password was to use getText(), which returns a String object, but it has been...

Performing an action after a RowSort operation

I have a JTable and a TableRowSorter which I'd like to perform an operation after a sort is finished. I've been browsing the net, and so far I haven't had much luck. Initially I thought just a RowSorterListener would do the trick, but unfortunately it doesn't perform the operation after the sort is finished. Adding a MouseListener to t...