swing

Is update from EDT in swing an absolute rule or are there exceptions?

In Swing, the GUI is supposed to be updated by the EDT only, since the GUI components are not thread safe. My question is, if I have a single thread, other than the EDT, that is dedicated to update a specific component, and this component is not accessed by any other thread in my program, only this dedicated thread, is it ok? In my case...

Thread-confinement/swingworkers

I am not clear about thread confinement. In swing all the gui components must be updated through the EDT. SwingWorker is provided in Java6 for lengthy operations, and in the done method the gui components can be updated. My understanding was that the gui components in the done() method are updated in the EDT. Therefore there should be no...

adding behavior when closing a JFrame

I have created a JFrame and I would like to associate a specific behaviour when this JFrame is closed. Is it possible? ...

Compiler throw non static method can't be accesed from static context when there is no problem

import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Frame; import java.awt.Graphics; import java.awt.Color; import java.util.Random; public class dots { public dots() { init(); } public void init() { JFrame frame = new JFrame("Dots"); frame.setExtendedState(Frame.MAXIMIZED_BOTH); ...

Inserting Boxes in Netbeans designer

I'm trying to insert some spacers into a layout on JPanel. I've got 3 buttons and I'd like to put something similar to Box.createRigidArea(new Dimension(10, 0)) between them. Netbeans 6.9.1 doesn't seem to have an option to create them - is that true? Is there some workaround? ...

Layouts and minimal sizes

Hi, I'm trying to insert a new panel with a minimal size set onto an existing form. Unfortunately after I do this: this.add(scrap); this.moveScrapCentre(scrap); // runs setLocation(...) this.revalidate(); this.repaint(); (where this: JPanel with null layout, scrap: JPanel with box layout and children) the scrap gets resized to (0,0) ...

How long does it take for a JPanel to update it's height?

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; public class dots extends JPanel implements KeyListener, ComponentListener{ //JPanel extended so that we can overwrite paintComponent and draw the dots, KeyListener so that we can capture keypresses Random rand = new Random(); JFrame frame; bo...

automatic font resize

Hello, How can I find out, if a text in a JTextField is larger than visible area of these JTextField, so that I can change the font size? Thx for any help. Sincerely Christian ...

Migrating a 2-tier Java application to...?

The title says it all. We currently have a 2-tier Java Swing application sitting on top of MS SQL Server 2005. All the business logic is in the database. The client is quite old (and not very friendly), and for reasons of performance and scalability, we've already started porting some services to a middle tier in Java. However, we st...

Where is the place to setSize of subcomponents

I have class extended from JPanel. This class contains several other JComponents and a lot of painting. What I did and I know it isn't correct is, I overrided the paintComponent for the paintings, so far so good. But I also set the location and the size for all subcomponents in this method, because they depend on the getWidth and getHe...

Wich is the best way to validate data in a JTextField?

I tried this, but the JTextField keeps showing the last key entered. What I'm I doing wrong?... private void codigoKeyTyped(java.awt.event.KeyEvent evt) { //codigo is the JTextField String s = String.valueOf(evt.getKeyChar()); try{ Integer.parseInt(s); }catch(Exception e){ codigo.setText(""); } } ...

JavaFX Scripts do not seem to work on other computers

When I bring my app to another computer the two buttons that should either open a file browser, or take in a file path to open a file both don't work. I don't understand why. It works perfectly fine if I compile it within Netbeans. package maxsublistsum; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; impor...

wait for a jdialog in non-modal mode

Hi, I have a JFrame and when the user presses a button is displayed an input jdialog. I need the jdialog to be in non-modal mode and once the user presses ok, I want to do some action based on the input. Right now I pass my view as reference in the jdialog, so that when the user presses ok, the jdialog calls a method of the view. Is th...

Disable Screenshot of my Swing Window

Hello, I have a Swing window that has sensitive information in it and I would like to prevent users from taking screenshots, or making by window invisible when they do take the screenshots. How can I achieve this? ...

Fixed width, variable height in JPanel with flow

I have an annoying problem with Java’s layout managers. I have the following situation: In a panel A are two other panels B with an absolute layout and C with a FlowLayout. B is highly customized and has a fixed size set via setPreferredSize. C should have the same fixed width as B but otherwise be of a variable height, depending on how ...

JFileChooser with confirmation dialog.

Hello: I am working on a program that loads and saves data from text files, and I am asking the user a file name with JFileChooser on load and save. This question is about the save dialog: new JFileChooser().showSaveDialog();. The user then could overwrite an existing file without any warning, and that would be a problem. Any suggest...

Item always selected in JTable

I have created a JTable where the included items are provided with radio buttons in order to enable users to select any of these once at a time. In order to show always the first item selected when the JTable is initialised (or when the item previously selected has been deleted) what method should I use? ...

JTable data update flickering, client-server model

Hello All, I know many times already talked about this problem but for me non of them helped. I have a client-server application which communicate via sockets. The method is the following: Client make a request to the server Server receive the request, process Send back the requested data via XML The JTable update / populate with ne...

JMenuItem shows checkbox on the left, how to disable it? (fixed)

Hi, I'm building a drop down menu which resides in program menu bar and pops up a JPopupMenu if a JButton gets clicked. In the JPopupMenu there are multiple JMenuItems. However, beside every JMenuItem it shows a checkbox! Which looks like this: I don't think it should, and there is explicit JCheckBoxMenuItem for that. Does anyone ...

paintComponent and getTableCellRendererComponent not getting called

I am setting the renderer of a JTable using setDefaultTableRenderer. JTable table = new JTable(); table.setDefaultRenderer(Object.class,MyRenderer); MyRenderer extends DefaultTableCellRenderer and overrides paintComponent and getTableCellRendererComponent. I have 4 rows and 8 columns and for strange reason my renderer methods are not...