swing

Memory Leak with Swing Drag and Drop

I have a JFrame that accepts top-level drops of files. However after a drop has occurred, references to the frame are held indefinitely inside some Swing internal classes. I believe that disposing of the frame should release all of its resources, so what am I doing wrong? Example import java.awt.datatransfer.DataFlavor; import java.io...

How to display image in Swing? in textarea?

Hello, I am creating a chat application using JApplet. I have a TextArea where all chat messages go. Everything in working fine and smooth just as you would expect a basic chat application to do. Now i want to add support for gestures. I wanted to know, how can we show an icon in textarea? it only takes string in append() method. Thanks ...

How do scroll the contents to bottom by default in JTextPane?

Hello, I have JTextPane on my window and i have JTextField. When i press enter enter in JTextField, the text gets added in JTextPane. Everything works fine and scrollbar too appears on its own. But, it doesn't appear properly. It automatically scrolls to the beginning of the content in JTextPane. How do i keep the scrollbar to the end of...

Java Swing GUI exception - Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException: Vector Enumeration

I get this exception when i run my application. I dont have any idea what is going wrong here. Can someone help please. Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException: Vector Enumeration at java.util.Vector$1.nextElement(Vector.java:305) at javax.swing.plaf.basic.BasicTableHeaderUI.getPref...

How to use Map element as text of a JComboBox

I am populating a JComboBox (using addItem()) with all the elements of a collection. Each element in the collection is a HashMap (so its a ComboBox of Hashmaps..). My question is - Given that I need each item to be a HashMap how do I set the text to apear in the combobox on the GUI? It needs to be the value of a certain key in the map...

logging problems for swing applications

what kind of logging frame work or API to use for swing applications which is used by multiple users in Unix. Is it possible to log all verbose/exception in one file per day or event one user one file per day? Since the user can open the same application with multiple instance. I also have another solution is to save the exceptions into...

UI not updated while using ProgressMonitorInputStream in Swing to monitor compressed file decompression

I'm working on swing application that relies on an embedded H2 database. Because I don't want to bundle the database with the app(the db is frequently updated and I want new users of the app to start with a recent copy), I've implemented a solution which downloads a compressed copy of the db the first time the application is started and ...

Is possible to make sexy GUI with javaFX & swing ?

I would like to do a "sexy" / user-friendly / appealing GUI in java. Swing is a limited in terms of "skin" customisation. I'm thinking about JavaFX but I don't it yet, what can I achieve with this technology ? how hard is it ? do you have examples of real-life examples of Swing/JavaFX integration ? I would like to do something in t...

About GridLayout.

Hi, if I have code like so: class X extends JFrame { X() { setLayout(new GridLayout(3,3)); JButton b = new JButton("A-ha"); /*I would like to add this button in the center of this grid (2,2)*/ //How can I do it? } }; Thanks. ...

Is it the most common case?

Why when I click on the x button to close the window in a Java application only the window dissapears and the applicaton is still running. I've read so many times that java designers tried to cater Java behaviour for the most common needs of programmers and save they precious time and so on and so on. What's more common case than closin...

create an hotspot and set an image without background (like earth icon) to my panel

Hi I try to create a hotspot by Extends of canvas and I try to add it on a panel which is painted by images. So I must draw an icon (image) instead of clear rectangle of the screen. To do that I override the paint method to draw the icon I want to use. So far there is no problem; the hotspot works correctly and the icon is painted i...

How can I set the save path for new files in JFileChooser?

I have a dialog using JFileChooser. When I save a file by FileOutputStream, I want to save it as file.txt in the path which the user want. But it always saves in c:/user/Document. Here is the code: DownLoadDialog downloadDialog = new DownLoadDialog(); int result = downloadDialog.showSaveDialog(queryPanel); if (result == downloadDialo...

create images clickable on jpanel

hi How i can add icon (car, earth or other) image that can be clickabel by user? i want to add them on an jpanel with overrided paint method. ...

Manually position JComponent inside JPanel

I want to programmatically move my JLabel to a specific location inside my JPanel. I have tried setLocation(int x, int y), but it doesn't work. I am trying to not use any layout manager. ...

What tool for printing Invoices and similar documents in Java Swing?

I'm looking for a good tool for printing Invoices, Receipts and similar documents in Java Swing. I have tried JasperReports but it is pretty hard to get a dynamic layout and it is designing for reports. A requirement that I have is that the document should be sent directly to the printer and must not be saved to a file. So some tools th...

Java JTree - How to check if node is displayed?

Looking for how to traverse a JTree (can do that) and check to see each node to see if it's displayed (to the user) or not visible. Can't believe JTree doesn't have this function, maybe I'm missing something? ...

Using JLists and ListModels

I have defined a DirectoryListModel class that extends the AbstractListModel class from the Java Api. Internally, I have a list of File objects. I have defined the getElementAt(int index) method as: @Override public Object getElementAt(int index) { return directoryElements.get(index) } The problem is that when I try to run my JLi...

How to change the cursor blink color?

I don't know this is possible or not? But i want to change the this cursor blink color...which is normally black.... i am making one java-swing based project and in that...one of the requirement is to change the color of the cursor blink.... Is this possible? ...

Capturing keystrokes in a panel in java

I want to capture keystrokes when the focus in on a panel in java. What should i do? I am using Netbeans as the IDE. I tried adding keyTyped event but it doesnot work. Here goes my code import com.lanadmin.Interface.ClientInterface; import java.awt.Toolkit; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import jav...

What's the easiest way for a Java Swing client to consumer a webservice?

I have a Java Swing application client that I want to use to consume certain webservices, but I want to make it as painless as possible to code (because really all I want is the info). I do understand that whatever solution is used will need to stub the POJO's too. If you'd like to give a demo, that would be great, or if you can point t...