swing

setting something disposed or invisible java

changed the project since its working now. kinda. the image still isnt changing. package icnon; import javax.imageio.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class FrameIconExample extends JFrame implements ActionListener { JLabel j; JPanel p, l, k; JButton picOne, picTwo; Container...

Sequence of the Events in Java

Hi, I have two events for two seperate components, but there is a problem. JTabbedPane's stateChanged event is fired before JFormattedField's focusLost event. Is there a way of making stateChange event to be fired after focusLost event. Thanks, Tuna ...

Create servlet from existing Java project

I have a Java Swing project for my class. I would like put it on my website so people can use it. However I'm not sure if there is a way to turn it into a servlet. Or do I need to know JavaScript? I'm confused. Is there a way to make my swing application into a servlet automatically? ...

How to display a tree of objects in a JTree?

Imagine a collection of objects such as World, Country, Region and City. World contains a list of Country objects, Country contains a list of Region objects etc. I would like to represent this structure in a JTree and be able to add, remove and move objects around the tree. Can I easily create a TableModel from this structure? World wo...

Java Swing architecture for flipping through JPane based views

Hi all, I have done a couple of simple swing based apps with static layout, but now I've run into a problem while trying to create an app containing multiple views which are changed by pressing appropriate navigational button. You could compare the idea to a website so that every view has buttons to access certain other views but this ...

Minimizing and Restoring Swing Window Breaks Layout and Repaint

I've written an application in Swing that listens for UDP packets from a smart battery and displays them in JTextFields inside a JPanel inside a JFrame. For some reason, minimizing the application and then restoring it smooshes all the text inside the center of the main frame and prevents updates to the JTextFields to be drawn to the ...

Java Swing: implement TableModel or extend AbstractTableModel?

When should I rather implement TableModel and when should I extend AbstractTableModel? ...

Java Swing: How does using a JTable work?

I am trying to build a little Table to show appointments. Here is what I have so far. Maybe you can give me a hint about what I am doing wrong, or which way to go. public class AppointmentTable extends JFrame{ public static void main(String[] args) { JTable table = new JTable(new AppointmentTableModel(1...

How to use a delay in a swing application

I am building a swing application. At some point, I have to start an "animation": ... jpanel1.setBackground(Color.Black); Delay(milli) jpanel1.setBackground(Color.White); ... and so on. The gui itself and all the logic behind it work.It is just this time depended color-changing that does not. I have read, that swing is not threa...

Open a window-popup from JMenuItem java

I have a JMenu with a JMenuItem, and when I click on this, I need to open a JFrame or window, in other words a component with inside JButton, JTextField,... How can i do this ? ...

How to set specific column settings in JTable?

How can I make my JTable show specific stuff for each column? Can I use an Object for more than one column? I want to have a column showing the date (dd.mm.yyyy) and another to show the time (hh:mm) but as I have it now it only shows the String representation of the Date object as a whole. public class AppointmentTableModel extends Abs...

Add a Component to two different JTabbedPanes

I have a LinkedList of Components, each of which I would like to add into two different JTabbedPanes. For some reason, Swing is only letting me put each component into one or the other. The code I'm using is the following: /* The two tab panes */ JTabbedPane leftTabs = new JTabbedPane(); JTabbedPane rightTabs = new JTabbedPane(); for (...

How to select item in jComboBox

Hi folks, I have a jComboBox that I am populating with some objects. The objects are of a type which I have made myself, and include a String and an int. The object's toString method returns the String, which is displayed in the Combo Box. Now, I wish to select an item in the Combo Box with code. How do I do this? There are multiple i...

Java Swing: How to add a CellRenderer for displaying a Date?

I have a Table: public class AppointmentTableModel extends AbstractTableModel { private int columns; private int rows; ArrayList<Appointment> appointments;... So each row of the table contains one Appointment. public class Appointment { private Date date; private Sample sample; private String comment; pri...

How to omit the "Cancel" button in Java ProgressMonitor ?

My task is necessary and shouldn't be canceled, how do I ask ProgressMonitor not to display the "Cancel" button, so when it finishes, it will auto close the panel. Frank ...

PNGException "crc corruption" when attempting to create ImageIcon objects from ZIP archive

I've got a ZIP file containing a number of PNG images that I am trying to load into my Java application as ImageIcon resources directly from the archive. Here's my code: import java.io.*; import java.util.Enumeration; import java.util.zip.*; import javax.swing.ImageIcon; public class Test { public static void main( String[] args ) ...

How to keep the popup menu of a JComboBox open on populating it ?

I have a JComboBox on my Panel. One of the popup menu items is 'More' and when I click that I fetch more menu items and add them to the existing list. After this, I wish to keep the popup menu open so that the user realizes that more items have been fetched however, the popup closes. The event handler code I am using is as follows publi...

Changing The Underlying Background Color Of A Swing Window

As discussed here, when resizing a Swing application in Vista (and Windows 7, which is what I'm using) you get a black background in the right/bottom corner while Swing's repaint catches up to the changes. Playing with other applications (Windows Explorer (Native), Firefox (C++?), and Eclipse (Java)) I notice that they all have this sam...

Change table cell color in Java

I have read and implemented this http://stackoverflow.com/questions/818287/changing-jtable-cell-color What I'd like to know is how to actually use this code? I just want to change a table cell's colour when I click on it. ...

How to add support for resizing when using an undecorated JFrame?

I would like to customize my titlebar, minimize-, maximize- and the close-button. So I used setUndecorated(true); on my JFrame, but I still want to be able to resize the window. What is the best way to implement that? I have a border on the RootPane, and I could use MouseListeners on the Border or the RootPane. Any recommendations? imp...