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...
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...
I have created a JFrame and I would like to associate a specific behaviour when this JFrame is closed. Is it possible?
...
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);
...
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?
...
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) ...
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...
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
...
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...
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...
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("");
}
}
...
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...
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...
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?
...
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 ...
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...
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?
...
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...
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 ...
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...