swing

How to make JOptionPane.showConfirmDialog have No selected by default?

I implemented a Save As dialog in Java that prompts the user if the file already exists, and I want the No option to be selected by default. How do I do this? Here is my current code: JFileChooser chooser = new JFileChooser() { public void approveSelection() { File selectedFile = getSelectedFile(); if (selectedF...

Sun Java Tutorials for earlier versions of Java?

Hi, I'd like to read the Sun Java Swing tutorials for Java version 5. It's easy to find Sun's tutorials for SDK 6. My searches of Sun's site and using Google didn't turn up any links (yet) to the older tutorial. Even the tutorial link on the SDK 5 page pointed to the current tutorials. Are the older tutorials still available? If so...

In Swing, how to provide priority to user interaction when many components are constantly requesting a repaint?

Swing newbie question... I have a system where there is a large number of independent widgets in the window (think >100) getting asynchronous updates and then requesting a repaint. When these widgets get updates very very fast, they seem to overload the Swing event thread so that user interaction (e.g., right clicking to display the con...

MouseListener on JFrame

I want to be notified of mouse events (specifically the mouse entered and exited events) on my JFrame. But when i add a mouselistener to it i get the events on the borders of the frame not the entire frame with it's contents. Any ideas as to why? EDIT : Or at least do you have an alternative? I want a "gloabal" way to catch mouse even...

Select all data when start editing JTable Cell

Hello! I'm trying for a long time to make a table that works like Excell do. It means, when user starts to insert data into the cells the content into them is selected and changed by the new data inserted. I don't know how to do it, I googled it a lot and didn't give any good idea. All the best! ...

Select next cell JTable

Hi, I would like to make a JTable that users when selecting an uneditable cell the it changes the focus to the next editable cell automatically. Important: the user could select a cell by keyboard (tab or arrow) and by mouse clicking. Is it possible?? How to to it? All the Best! ...

How to get windows logon credentials from a Swing application?

How would I go about getting the Windows user credentials from a Swing application? I am working on an internal (corporate) Swing application. Currently the user has to login to the application using a login screen, which then connects to an app server which authenticates the user against the company LDAP server. Since the user has alr...

Using an ActionListener in one class to start a timer in another class.

I have a class (simulation) which creates an instance of another class (GUI). Inside the class GUI there is a button (start) which has an actionlistener attached to it. I need this actionlistener to start a timer in simulation but I can't figure out how to do it. Code in Class Simulation: public class Simulation{ private static JFram...

Easy way to fill a JTable with CSV data

I have CSV data (in fact the values are separated by a tab character, but I can use ; as the separator). The data are stored in a String object. Is there simple way to create a JTable with this data (without doing it manually by reading and parsing the String object) ? (note: my project is using Java 1.4, but if you have a solution tha...

JTable using Swing

HI, I am new to programing world. I want to know how to generate dynamic table using java swing component. I like to know how rows are generated dynamically where column remains fixed. Please anybody can help me out ...

Shifted text in swing app on OS X

Hi I have a little java+swing app. Until now it worked OK, on OS X and on windows. But recenly a user has noticed that on his OS X (version unknown yet, nor the java version) that all texts in the GUI are shifted up and cut (as you can see on the screenshot). And HTML link is shifted down and cut. All those elements are JLabels. Th...

Calling JFrame.setGlassPane(Component) more than once

Is there any trick to calling JFrame.setGlassPane(Component) more than once? In the code below, I first call it to create a red box in the glass pane. That works fine. Then, in a mouse click handler, I call it again to create a blue box in a new glass pane. This doesn't work. The original red glass pane disappears, but the blue glas...

Detecting a JRadioButton state change

How can I detect when a JRadioButton is changed from 'unselected' to 'selected' when clicked with the mouse? I've tried using an ActionListener on the button, but that gets fired every time the radiobutton is clicked, not just when it's changing state to 'selected'. I've thought of maintaining a boolean variable that remembers the state...

when i execute get LDAPConnection thorugh Swing it hangs!!!

When I run following code through Main method, it works fine but when i try to execute it on click of swing button, it hangs. Please help import java.util.Hashtable; import javax.naming.AuthenticationException; import javax.naming.Context; import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.nami...

Swing Overlapping components

I have two AWT components in a Frame, Panel A and Panel B. I would like panel A to be sized to the height width of the frame (and maintain that size on frame resize), but I would like panel B to overlap A. B will be at a fixed position (0,0 to make it easier) with a fixed height and width. I'm not sure what kind of layout manager I would...

In Swing, Is there a way to temporarily freeze repainting of a JComponent containment hierarchy?

If I have a bunch of custom JComponents in a Swing panel, and each of them can contain many other JComponents, is there a way to "freeze" repaints on the top level components and then unfreeze them, triggering a repaint? I guess I am trying to do sort of a localized double-buffering. ...

What happens when Swing's threading policy is violated?

In the past few years I've mostly done UI development in Eclipse, which is very conservative in terms of thread access: any attempt to change a property on a UI widget (e.g., color, text) from outside the UI thread throws an exception. I am now looking at an existing program in Swing that has a window with a large number of custom widge...

JasperReports rendering problem

I have a very weird JasperReports rendering problem. I am using an old version of the free Java Reporting Tool JasperReports: 1.3.4. It's being heavily used on a Swing finance application. I use JasperViever class to show a preview of the report to print, and my weird problem is that the report shows perfectly fine on some computers wh...

JWindow alway on top not getting focus events.

I have a jwindow(set to be always on top) that you can click to get a pop menu. If the user right clicks the window it shows the pop menu but then if the user clicks any other window(such as firefox) pop menu does not disappear. I tried to fix it by adding FocusListener on the jwindow, i implemented FocusListener and override pub...

How do you create a javax.swing.Timer that fires immediately, then every t milliseconds?

Right now, I have code that looks something like this: Timer timer = new javax.swing.Timer(5000, myActionEvent); According to what I'm seeing (and the Javadocs for the Timer class), the timer will wait 5000 milliseconds (5 seconds), fire the action event, wait 5000 milliseconds, fire again, and so on. However, the behavior that I'm tr...