swing

Open new panel with button clicked.

Java Swing GUI: I am using ActionListener to preform the action when a button is clicked. What i want to do is when a button is clicked, open a new panel, but load/get the new panel from a different file. This is what i have so far but i rather just link to another file. THANKS! =] public void actionPerformed(java.awt.event.ActionE...

Java Swing- Create a function to add elements to JScrollPanel

I want to create a function so that i can call add JLabel's, etc inside the JScrollPanel. I am not sure what the command is in NetBeans. I tried doing JScrollPanel -> events -> container -> componentAdded to create the code below. But nothing shows up when i add code to that function. private void initComponents() { scro...

Swing and handling threads

There's a couple questions here on StackOverflow on the subject of threading with the Swing api but things still aren't clear. What is the issue with the EDT, what is the proper way to initiate a Thread with Swing and in what cases should it be used? P.S: Any sources in terms of good practises would be appreciated. ...

BufferedImage.getGraphics() resulting in memory leak, is there a fix?

Hi friends, I'm having problem with some framework API calling BufferedImage.getGraphics() method and thus causing memory leak. What this method does is that it always calls BufferedImage.createGraphics(). On a windows machine, createGraphics() is handled by Win32GraphicsEnvironment which keeps a listeners list inside its field display...

Java Swing: JTextArea columns question

How do i put the text in specific columns with jTextArea? private javax.swing.JTextArea jTextArea1; jTextArea1.setColumns(4); jTextArea1.insert(price, 0); //column 1 jTextArea1.insert(cost, 0); //column 2 jTextArea1.insert(quantity, 0); //column ect.. jTextArea1.insert(itemName...

Why is my GUI unresponsive while a SwingWorker thread runs?

Hello, I have a SwingWorker thread with an IOBound task which is totally locking up the interface while it runs. Swapping out the normal workload for a counter loop has the same result. The SwingWorker looks basically like this: public class BackupWorker extends SwingWorker<String, String> { private static String uname = null; private...

How to configure database for exe.file

Recently I had created a Java Desktop Application, I wish to share it with my friends. I was thinking to convert it into exe file using exe4j, but as for the database part I not sure how to configure it so that the application can run on my friends desktop without re-configure the database again. I am using Microsoft Access, anyone can g...

Is it allowed to load Swing classes in non-EDT thread?

After the introduction of Java Memory Model, the Swing guidelines were changed to state that any Swing components need to be instantiated on the EDT in order to avoid non-published instance state. What I could not find anywhere is whether the classloading is also mandated to be on the EDT or can we pre-load key Swing classes in a backg...

Passing ActionListeners in Java, pack()

Two questions. First question is I'm trying to create a simple form that when you press a button, it adds a Person object to the ArrayList. However, since I am not used to GUIs, I tried creating one and am first just trying to get the user input from the JTextField, create an ActionListener object of the appropriate type, so once that ...

removing horizontal scrollbar for textarea

Hi. I'm using Java Swing. I have a textarea in a panel. I don't need a horizontal scrollbar for that textArea, only a vertical scrollbar is needed. I disabled auto scrollbar options, but still the horizontal scrollbar is working. Please help me in thz. ...

Allowing users to resize columns of JTable

Im creating a table which is dynamically changing its width. And I add columns by time as well. And I have bounded this table to a scrollpane. Here I have set the auto resizing to false in the JTable (else it will fill the whole area from the beginning). And I'm adding images to cells using cellrenderer as well. Now I need to allow use...

Change font size of a JPanel and all its elements.

Hello all, I am trying to create a Swing panel whose elements have a different font size than the rest of the swing application. Initially, using setFont for a couple of components didn't pose any problems. Now I have several components (and all their subcomponents), so this solution is impractical. I have searched about changing the d...

call a method at a specified time

How can I call a method every n seconds? I want to do a slideshow with Swing and CardLayout and every n seconds it must show a different image calling a different method ...

How to drag-and-drop on custom Swing components

How can I implement drag and drop on custom components, e.g. my own JPanel subclasses? What I need is full Swing-like drag and drop support. With TransferHandlers, DropTargetListeners etc. So the trivial mousePressed() and mouseReleased() is not what I'm looking for. ...

Is Java Swing still in use?

I am planning on making a Java Swing application and was wondering if Swing is still used or if it has been replaced with something else. Thanks in advance! ...

How to make a swing app aware of screen size change?

Hi, while my swing app is running I change the size of the screen (e.g. from 1024x768 to 800x600). Is there any event I can listen to to be notified about this? Alternatively I could check the screen size in every couple of second, but the Toolkit.getScreenSize() keeps telling me the old value. How could I get the real screen size aft...

Switching Between Cards in a CardLayout using getParent()

Hey everyone, I am writing an application where I am using the CardLayout to swap between two panels that are placed right on top of one another. There's a JPanel called Top, and it's layout is the CardLayout. Inside this JPanel is a JPanel called CMatch. Whenever the user clicks the submit button in the CMatch panel, I want a new JPan...

Swing UI does not have native OS look

I am building an application in java swing and I am using the following code to give the UI a native OS look try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } On a OS X, the look is fine, but on windows (XP and 7) the buttons look like this. I have...

Custom Swing component: questions on approach

Hi Folks, I'm trying to build a new java swing component, I realise that I might be able to find one that does what I need on the web, but this is partly an exercise for me to learn ow to do this. I want to build a swing component that represents a Gantt chart. it would be good (though not essential for people to be able to interact ...

Simple popup java form with at least two fields

This is, I suppose, a very simple question for any Java programmer. My question is as simple as this: When the user clicks a button, I want to show a popup form that should have at least two JTextFields and two JLabels, so using JOptionPane.showInputDialog is not a possibility. Thanks. ...