Jfilechooser info
HI
I'm using Jfilechooser to open/save files.
I have some question:
1) The filechooser language is italian, now I want to show it with english language...
2) in the save filechooser, i want to save xml files, so I wanna show in the "file name" field something like a "*.xml" string, and I wanna cut the file type filter field (or at least to show only directory and xml file).
How could I do both of them?
tks
GG
Cross-Post:
http://forum.java.sun.com/thread.jspa?messageID=4234042
Thanks for wasting our time.
Similar Messages
-
For the past few days I have been struggling with creating a GUI for a program I am developing with the aim of extracting index.dat files. The user selects the file they wish to analyse, the program outputs various details to the interface. However, I am having issues trying to implement this with the JLabel 'size'. Others such as the JTextAreas have not yet been attempted.
The program itself runs fine in the background however, none of the details are added to the interface itself.
The following is the code I have so far for implementing the GUI, apologise if this seems messy, however I have been editing it quite abit recently trying to solve the issue. Not all aspects of this program have been implemented yet, such as methods for editing the JTextAreas, as I am currently just trying to solve the setIndexInfo() method when editing the 'size' JLabel.
public class GUInterface extends JFrame implements ActionListener
//creating GUI variables
JMenuBar menuBar;
JMenu file;
JMenuItem historyItem, flashItem, exit;
JFileChooser filechoose;
JPanel info, top, output, cacheDisplay;
JTextArea cache, display;
JLabel type, loc, size;
JScrollPane scrollpane;
File f = new File("C:\\");
String locStr;
public void create()
guInterface();
}//end create
public void guInterface()
//initialising variables
menuBar = new JMenuBar();
file = new JMenu("File");
historyItem = new JMenuItem("Index.dat");
flashItem = new JMenuItem("Flash Cookies");
exit = new JMenuItem("Exit");
filechoose = new JFileChooser();
info = new JPanel();
top = new JPanel();
cacheDisplay = new JPanel();
cache = new JTextArea(9, 10);
type = new JLabel("AnalysisType");
loc = new JLabel("FileLoc");
size = new JLabel("Size");
//creating menu bar
menuBar.add(file);
file.add(historyItem);
file.add(flashItem);
file.addSeparator();
file.add(exit);
//info
info.setLayout(new BoxLayout(info, BoxLayout.Y_AXIS));
type.setFont(new Font("Serif", Font.BOLD, 30));
info.add(type);
info.add(Box.createRigidArea(new Dimension(0,5)));
loc.setFont(new Font("Serif", Font.BOLD, 20));
info.add(loc);
info.add(Box.createRigidArea(new Dimension(0,5)));
size.setFont(new Font("Serif", Font.BOLD, 20));
info.add(size);
//cacheDisplay
cacheDisplay.add(cache);
cache.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
cache.setMaximumSize(new Dimension(200, 200));
cache.setLineWrap(true);
cache.setEditable(false);
cache.setSize(200,100);
//top panel
top.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS));
top.add(info);
top.add(Box.createHorizontalGlue());
top.add(cache);
filechoose.setCurrentDirectory(f);
historyItem.addActionListener(this);
flashItem.addActionListener(this);
exit.addActionListener(this);
setJMenuBar(menuBar);
//JFrame layout
setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
//creating main area
setSize(1000, 600);
setLocationRelativeTo(null);
setTitle("PrivateBrowse - Private Browsing Recovery Tool");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}//end guInterface
public void setIndexInfo(String output)
size = new JLabel(output);
size.setFont(new Font("Serif", Font.BOLD, 20));
}//end setIndexInfo
public void actionPerformed(ActionEvent evt)
if(evt.getSource() == historyItem)
filechoose.setDialogTitle("Select index.dat");
filechoose.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(filechoose.showOpenDialog(null) == filechoose.APPROVE_OPTION)
type.setText("Index.DAT Analysis");
locStr = filechoose.getSelectedFile().toString();
loc.setText(locStr);
try
IndexRecovery idxRcvy = new IndexRecovery();
idxRcvy.readFile(locStr);
catch(Exception e)
System.out.println("Error: " + e);
else if(evt.getSource() == flashItem)
filechoose.setDialogTitle("Select #SharedObjects Directory");
filechoose.setApproveButtonText("Select");
filechoose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(filechoose.showOpenDialog(null) == filechoose.APPROVE_OPTION)
type.setText("Flash Cookie Analysis");
locStr = filechoose.getSelectedFile().toString();
loc.setText(locStr);
try
FlashRecovery flshRcvy = new FlashRecovery();
flshRcvy.extractFlash(locStr);
catch(Exception e)
System.out.println("Error: " + e);
else if(evt.getSource() == exit)
setVisible(false);
dispose();
System.exit(0);
}//end actionPerformed
}The class IndexRecovery calls setIndexInfo() with the size wanted to be displayed in the JLable 'size'.
I have been looking around and heard of various functions such as repaint() and validate(), however have no clue how to use these should these be the solution.
Any advice on the matter will be greatly appreciated.
Thanks,
David.public void setIndexInfo(String output)
size.setText(output);
}//end setIndexInfoOr this, to be thread safe:
public void setIndexInfo(final String output) {
if (SwingUtilities.isEventDispatchThread()) {
size.setText(output);
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setIndexInfo(output);
}//end setIndexInfoEdited by: Andre_Uhres on Apr 6, 2010 4:58 PM -
Hi,
I have a File[] array (with directories and files on it), and want to take to another array the size of files only. I don't want to use File.length, because in this way i take the size of directories too.
I tried to use this:
for(int i=0; i<array.length; i++)
File f = new File(path, array.toString());
Size[i]=f.length();
}//for
but i don't think is good to have a Size array with "zeros" (when it finds directories) and long values (when it finds files).
What do you propose me to do?
Would it be good to use JFileChooser and how?
Thanks,
TSolonelWhat do you want to do with that array? Why not having a File[] array, so you have both length and isDirectory info. Sorting? Something else? JFileChooser seems irrelevant. But again, it's all up to what you are trying to do. Clarify
-
Problems with JFileChooser and Windows 2000 (can't see mydocuments contents
Hi! I've an applet which has a JFileChooser component. In other Windows, I can select the MyDocuments folder and it goes there and list all the contents OK. But, in Windows 2000, when I go to MyDocuments, none of the contents is listed in the file chooser. I need to navigate through all the directories to get there (C:\documents and settings\user\my documents) and then, it shows its contents, but obviously, I don't want it to be this way because is difficult for the common user.
Any idea of why is going on this?
Thanks in advance!Hello, You need to use something like o=isp as the
root DN, then o=yourorg.com goes beneath it.
i.e.
For the other questions on setup, just choose o=isp
as base DN when you set up the directory server. When
you run ims_dssetup.pl, choose o=internet as the DC
tree base, then choose o=isp as the user/groups base
suffix.
When you are installing messaging server it will ask
where to put the default organization, this is where
you would choose o=abc.com, o=isp
For more info on how this structure works please take
a look at this link and it will all fit into place:
http://docs.sun.com/source/816-6017-10/changes.htm#170
8Alright, I got ims_dssetup to run successfully. But now when the ims 5.2 installation is about 50% done, I get the message:
A serious problem occurred while installing the iPlanet Messaging Server Messaging SIE entry in LDAP (msg.cfgldap.sie.inf). It reported the following problem:
The server configuration for the Messaging SIE entry in LDAP (msg.cfgldap.sie.inf) cannot be created. -
JFileChooser strange registry error
I am testing a java application on windows 7 and just saw a very strange error pop up after trying to use a JFileChooser:
An error was detected in the windows registry.
Required windows folders were missing.
Googling this did not turn up anything obvious.
Clicking OK then showed:
Some local folders are missing.
Missing: C:\programdata\OEM Links
Full folder List:
C:\Users\Public\Desktop
... (other folders)
Anyone ever seen anything like this before?
Or anyone have an idea what might be going on?
This is a fresh win7 install on a test box (ghosted for re-imaging)
why does JFileChooser care about the registry?Hello,
I'm sorry you haven't got a reply so far. Here are some considerations, that you can now wish to consider:
I am testing a java application on windows 7 and just saw a very strange error pop up after trying to use a JFileChooser:Can you test it on another version of Windows? What is the result?
If you don't have any other Windows version available, can you post an SSCCE (a 10-line program that tries to open a JFileChooser, and reproduces the problem), so that you, me, and other people, have a chance to run the exact same test on various OS?
In all cases, you always have more chance to receive an answer when you post an SSCCE that demonstrates the problem with convenience for other forum users: http://sscce.org
An error was detected in the windows registry.
Required windows folders were missing.
Googling this did not turn up anything obvious.Googling "JFIleChooser registry" did turn up a few interesting links, see below.
Some local folders are missing.
Missing: C:\programdata\OEM Links
Full folder List:
C:\Users\Public\Desktop
... (other folders)Anyone ever seen anything like this before?
Or anyone have an idea what might be going on?From the looks of it, it seems the JRE is using the registry to have some info about the files system. I don't know for sure which info and why, but I don't find that so surprising (admittedly, the error message itself is rather unclear).
why does JFileChooser care about the registry?Not the registry itself, but merely the info it contains about the filesystem's structure. I imagine drive names and mapping of network drives can be found there, for example.
As claimed above, Googling led me to the following bug entries:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4879395
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4712307
Don't necessarily traverse the whole contents of the bug entries themselves: the point is that they prove that the JRE is indeed leveraging filesystem info from the registry (the reason was, if I understand correctly, to improve performance in the case of network drives, and in the case of very numerous files).
The other point is that both bug entries describe the same command-line flag to disable at least one mechanism that leverages the registry:
java -Dswing.disableFileChooserSpeedFix ...Hopefully, that may, with no guarantee, fix your specific issue. Try it and let us know.
Best regards,
J. -
Huge combo boxes in JFileChooser/JList text truncated in 1.4.0
Hi there,
We have an application which works fine on Sun JRE 1.3.1
Recently we started supporting Sun JRE 1.4.0
But we have some problems with GUI in Sun JRE 1.4.0
In the JFileChooser dialog the combo box for Folder name
and file filter is atleast twice as big as normal in when
using JRE 1.4.0. This seems to be happening only in some particular
machines. And if we run the application using JRE 1.3.1, on the machine which has problems with JRE 1.4.0, everything works fine.
Also we use a JList with a custom cell rendered in the application.
the cell renderer returns a JLabel component with "monospaced" font set in it. In some machines (same machines which has the JFileChooser problem) the upper half of each item in the JList is truncated. This also works fine is we use JRE 1.3.1 on the same machine.
Please help me if you have any info on these issues.
Any pointers to related issues on this forum or bug database is highly appreciated.
Thanks in adanceHehe. Give it more time. Could you explain more about what you mean?
You have a form with the select combo box in it. The user chooses a value from the combo box. Then submits the form. You want to put the value of the option inside the sql statement right? Not the words displayed by the option, but the item you put in the value section right?
If so, its rather easy:
query = "INSERT INTO Table VALUE( comboType, \""+request.getParameter( "text")+"\"); The \" might not be necessary depending on how the value is stored. -
JFileChooser, multiple dialogs.
My JFileChooser is getting the path and filename for a file, to be later opened. I'm placing the path and name in a JTextField.
My problem is this: whenever I click 'Find' and select my file and click 'Open', the path and filename show in the JTextField, but the dialog reopens as though I'm pressing the 'Find' button again.
Here's my source:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.filechooser.*;
public class mm5 extends JFrame implements ActionListener
String[] sItems = new String[1]; // Stores item titles loaded from file. Will be displayed in JList: lstItems
String[] sProgram = new String[1]; // The program that is ran when the script is executed.
String[] sLocation = new String[1]; // The location the program tries to open when the script is executed.
int[] iTimer = new int[1]; // A value of zero will tell the program that this is a schedule-based item instead of a timer-based one.
int[][] iTimeDef = new int[1][1]; // The first field in this matrix contains the number of scheduled times the item will be called. The second field contains the hour in which the item will be called.
Border border1 = new EtchedBorder(EtchedBorder.RAISED, Color.black, new Color(165, 163, 151));
JFrame fraAdminPanel = new JFrame("Admin Panel");
JFrame fraAddItem = new JFrame("Add Item");
JPanel panBack = new JPanel();
JList lstItems = new JList();
JScrollPane scpItems = new JScrollPane(lstItems);
JButton btnRun = new JButton("Run");
JButton btnReport = new JButton("Report");
JButton btnInfo = new JButton("Info");
JButton btnHelp = new JButton("Help");
JButton btnAdmin = new JButton("Admin");
JButton btnExit = new JButton("Exit");
JLabel lblTime1 = new JLabel("Time");
JLabel lblTime2 = new JLabel("00:00");
JPanel panAdmin = new JPanel();
JButton btnAddNew = new JButton("Add New");
JPanel panAddItem = new JPanel();
JLabel lblItem = new JLabel("Item Title/Desc.");
JTextField txfItem = new JTextField(100);
JLabel lblProgram = new JLabel("Program");
JComboBox cbxProgram = new JComboBox();
JLabel lblLocation = new JLabel("Location/URL");
JTextField txfLocation = new JTextField(100);
JFileChooser fcLocation = new JFileChooser();
JButton btnLocation = new JButton("Find");
ButtonGroup btgTimer = new ButtonGroup();
JRadioButton optTimer = new JRadioButton("Timer");
JRadioButton optTimeDef = new JRadioButton("Scheduled");
JRadioButton optNull = new JRadioButton("");
JLabel lblTimer = new JLabel("Minutes");
JTextField txfTimer = new JTextField(3);
JLabel lblTimeDef = new JLabel("Schedule");
JTextField txfTimeDef = new JTextField(3);
JButton btnTimeDef = new JButton("Set");
JCheckBox cbxException = new JCheckBox();
JButton btnAdd = new JButton("Add Item");
JButton btnCancel = new JButton("Cancel");
public mm5()
try
mmInit();
catch(Exception e)
e.printStackTrace();
} // End of mm5()
public void actionPerformed(ActionEvent AE)
String sTheAction = AE.getActionCommand();
if(sTheAction == "Admin")
System.out.println("Admin button pressed.");
adminPanel();
else if(sTheAction == "Add New")
System.out.println("Add New button pressed.");
addNewInit();
else if(sTheAction == "Find")
System.out.println("Find button pressed.");
findFile();
} // End of actionPerformed()
public static void main(String[] args)
mm5 f = new mm5();
} // End of main()
public void mmInit()
this.setTitle("MultiMonitor 5.0.1");
this.getContentPane().setLayout(null);
centerWindow(700, 500); // Centers the window and sets the x,y size.
addWindowListener(
new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
panBack.setLayout(null);
panBack.setBounds(new Rectangle(5,5,695,495));
BackLstItemsInit();
panBack.add(scpItems, null);
BackBtnInit();
panBack.add(btnRun, null);
panBack.add(btnReport, null);
panBack.add(btnInfo, null);
panBack.add(btnHelp, null);
panBack.add(btnAdmin, null);
panBack.add(btnExit, null);
this.getContentPane().add(panBack);
this.setVisible(true);
} // End of mmInit()
public void BackLstItemsInit()
boolean EOF = false;
scpItems.setBounds(new Rectangle(5,5,575,450));
scpItems.setBorder(border1);
scpItems.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
lstItems.setListData(sItems);
} // End of BackLstItemsInit()
public void BackBtnInit()
btnRun.setBounds(new Rectangle(585,5,100,25));
btnRun.setActionCommand("Run");
btnRun.addActionListener(this);
btnReport.setBounds(new Rectangle(585,30,100,25));
btnReport.setActionCommand("Report");
btnReport.addActionListener(this);
btnInfo.setBounds(new Rectangle(585,55,100,25));
btnInfo.setActionCommand("Info");
btnInfo.addActionListener(this);
btnHelp.setBounds(new Rectangle(585,80,100,25));
btnHelp.setActionCommand("Help");
btnHelp.addActionListener(this);
btnAdmin.setBounds(new Rectangle(585,105,100,25));
btnAdmin.setActionCommand("Admin");
btnAdmin.addActionListener(this);
btnExit.setBounds(new Rectangle(585,130,100,25));
btnExit.setActionCommand("Exit");
btnAdmin.addActionListener(this);
} // End of BackBtnInit()
public void centerWindow(int windowWidth, int windowHeight)
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
this.setBounds((d.width - windowWidth)/2, (d.height - windowHeight)/2, windowWidth, windowHeight);
} // End of centerWindow()
public String[] enlargeArray(String[] currentArray)
String[] newArray = new String[currentArray.length + 1];
for(int i = 0; i<currentArray.length; i++)
newArray[i] = currentArray;
return newArray;
} // End of enlargeArray()
public void adminPanel()
System.out.println("adminPanel() started");
fraAdminPanel.setVisible(true);
fraAdminPanel.getContentPane().add(panAdmin);
fraAdminPanel.setBounds(50,50,100,200);
panAdmin.setLayout(null);
panAdmin.setBounds(0,0,110,200);
btnAddNew.setBounds(new Rectangle(5,5,100,25));
btnAddNew.setActionCommand("Add New");
btnAddNew.addActionListener(this);
panAdmin.add(btnAddNew, null);
} // End of adminPanel()
public void addNewInit()
System.out.println("addItem() started");
fraAddItem.setVisible(true);
fraAddItem.getContentPane().add(panAddItem);
fraAddItem.setBounds(50,50,325,250);
panAddItem.setLayout(null);
panAddItem.setBounds(0,0,325,250);
lblItem.setBounds(new Rectangle(5,5,200,25));
panAddItem.add(lblItem, null);
txfItem.setBounds(new Rectangle(5,35,200,25));
panAddItem.add(txfItem, null);
lblProgram.setBounds(new Rectangle(210,5,100,25));
panAddItem.add(lblProgram, null);
cbxProgram.setBounds(new Rectangle(210,35,100,25));
panAddItem.add(cbxProgram, null);
lblLocation.setBounds(new Rectangle(5,65,200,25));
panAddItem.add(lblLocation, null);
txfLocation.setBounds(new Rectangle(5,95,200,25));
panAddItem.add(txfLocation, null);
btnLocation.setBounds(new Rectangle(210,95,100,25));
btnLocation.setActionCommand("Find"); // Button for JFileChooser
btnLocation.addActionListener(this);
panAddItem.add(btnLocation, null);
optTimer.setBounds(new Rectangle(5,125,100,25));
optTimer.setActionCommand("optTimer");
optTimer.addActionListener(this);
btgTimer.add(optTimer);
panAddItem.add(optTimer, null);
optTimeDef.setBounds(new Rectangle(105,125,100,25));
optTimeDef.setActionCommand("optTimeDef");
optTimeDef.addActionListener(this);
btgTimer.add(optTimeDef);
panAddItem.add(optTimeDef, null);
optNull.setActionCommand("optNull");
optNull.addActionListener(this);
btgTimer.add(optNull);
lblTimer.setBounds(new Rectangle(5,155,100,25));
panAddItem.add(lblTimer, null);
txfTimer.setBounds(new Rectangle(5,185,100,25));
panAddItem.add(txfTimer, null);
lblTimeDef.setBounds(new Rectangle(105,155,100,25));
panAddItem.add(lblTimeDef, null);
btnTimeDef.setBounds(new Rectangle(105,185,100,25));
panAddItem.add(btnTimeDef, null);
btnAdd.setBounds(new Rectangle(210,155,100,25));
btnAdd.setActionCommand("Add");
btnAdd.addActionListener(this);
panAddItem.add(btnAdd, null);
btnCancel.setBounds(new Rectangle(210,185,100,25));
btnCancel.setActionCommand("Cancel Add");
btnCancel.addActionListener(this);
panAddItem.add(btnAdd, null);
} // End of addNewInit()
public void findFile()
fcLocation.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int iLocation = fcLocation.showOpenDialog(fraAddItem);
if(iLocation == JFileChooser.APPROVE_OPTION)
txfLocation.setText(fcLocation.getCurrentDirectory() + "\\" + fcLocation.getSelectedFile().getName());
System.out.println(fcLocation.getSelectedFile().getName() + " selected");
else
System.out.println("No file selected.");
return;
} // End of findFile()The problem is with he registration of actionListener for the find button.
This is being done in your code each time the AddNewItem is being
used. because of this each time you click Add New Item. another listener
is registered for the find button and hence the no. of times it will
show filechooser will keep on increasing.
Pravin -
Is there a free Remote JFileChooser?
Hello,
Does anybody know if there is code for a free Remote JFileChooser?
(that would be of great help and save the effort of reinventing the wheel)
thanks,
AnilThe problem is not in JFileChooser. That all stays
the same. What you want is a FileSystemView of some
remote location. I don't know that there is a
freeware or shareware version of such a thing
principally because it's not a well defined problem:
There are lots of ways + protocols you could
potentially query another computer for info about its
FS. In short, you probably have to do this yourselfThanks for replying. Apparently the only solutions I have seen involve installing server-side stuff. (not good)
http://www.fishcroft.ca
The user needs to Remote Save (via ftp) files to a unix box. Also I shall be using Webstart to run the application, so simply using JFileChooser wont do. If I code a solution, I shall post it here.
thanks,
Anil -
I want to disable textfield in JFileChooser ? how can that be done
i can give error msg , if user enters wrong info in textfiled. But i want to completely disable this textfield so that user cannot enter anything in that text field . Plz giv suggestions for it
Did you ever figure out a way to do this? I'm trying to do the same thing: I want the user to navigate the filesystem through the JList, but NOT be able to directly edit the contents of the textfield.
I think you may be able to search through the JFileChooser for the actual textfield, then set it to non-editable. I've looked at the contents of the JFiledChooser as a Component, but haven't found the textfield. Ideas?
[email protected] -
JFileChooser crashes JVM - bug basically ignored. What can I do?
See:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7160713
The bug has been marked as incomplete,needs more info, and "Low Prioroty" - Yet there is no mechanism to provide any more information. There is no way to add comments, or vote. The bug brings down the entire JVM with a native crash and it is trivial to reproduce.
I would provide any information that is asked of me - but I need a way to do it. I think I got an email request for info (It's been a while now), but replies to the email bounced, and as noted above the bug page has no way to give feedback.
Use any JFileChooser, click on the "Details" view. Then start clicking on column headings... after a few clicks the JVM crashes. Tested again with 7u6 - still crashes.This reproduces the problem more reliably for me.
* JFileChooser Windows Crash
package filechoosercrash;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
* @author scott
public class FileChooserCrash {
static CountDownLatch latch = new CountDownLatch(1);
static JFrame frame;
static JButton button;
static JFileChooser chooser;
static Robot robot;
private static AWTEventListener terminator = new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
System.exit(10);
* @param args the command line arguments
public static void main(final String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
swingMain(args);
} catch (Exception ex) {
Logger.getLogger(FileChooserCrash.class.getName()).log(Level.SEVERE, null, ex);
latch.await();
// do the clicks
sleep(3000);
Toolkit.getDefaultToolkit().addAWTEventListener(terminator, AWTEvent.KEY_EVENT_MASK);
long now = System.currentTimeMillis();
for (int c = 0; c < 10; c++) {
Window w = JDialog.getWindows()[1]; // better be there!
System.out.println("w=" + w);
int detailsX = w.getX() + w.getWidth() - 36;
int detailY = w.getY() + 50;
int headingY = w.getY() + 100;
System.out.println("details at " + detailsX + ", " + detailY);
// Click details
robot.mouseMove(detailsX, detailY);
clickMouse();
sleep(100);
// Click column headings
while (System.currentTimeMillis() - now < 2 * 1000) {
int headingX = w.getX() + (w.getWidth()/2) + (int) (Math.random() * (w.getWidth()/2));
robot.mouseMove(headingX, headingY);
clickMouse();
sleep(300);
// Cancel
robot.mouseMove(w.getX() + w.getWidth() - 36, w.getY() + w.getHeight() - 36);
clickMouse();
sleep(300);
// re-open
robot.mouseMove(frame.getX() + 36, frame.getY() + 36);
clickMouse();
sleep(1000);
now = System.currentTimeMillis();
private static void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException ex) {
private static void clickMouse() {
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
sleep(100);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
private static void swingMain(String[] args) throws Exception {
//switchToNimbus();
robot = new Robot();
frame = new JFrame("JFileChooser Crash Test");
button = new JButton("Start...");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showFileChooser(frame);
frame.getContentPane().add(button, BorderLayout.CENTER);
frame.getContentPane().add(new JLabel("Press \"Start...\" and let go of the mouse. Robot will be used to change FileChooser to details view and then quickly click column headings until the crash."), BorderLayout.SOUTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
static void showFileChooser(JFrame parent) {
chooser = new JFileChooser("C:\\");
latch.countDown();
chooser.showOpenDialog(parent);
private static void switchToNimbus() throws UnsupportedLookAndFeelException, IllegalAccessException, InstantiationException, ClassNotFoundException {
for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
if (laf.getName().startsWith("Nimbus")) {
System.out.println("Using " + laf.getName());
UIManager.setLookAndFeel(laf.getClassName());
break;
} -
How to make a dialog in front of JFileChooser
I used to save a file, i use JFileChooser for this,
I want validate the selected file for existance i.e if a user selects a file which is already exists, i want to show a info message in front of JFilechooser dialog
i.e it must hide iff i give a new file name.
How can i make JFileChooser to visible even after selecting Save button, but what now actually happens is JFileChooser hides and my custom info message appears in parent frame.
How can i make JFileChooser as a parent of my dialogCustomize JFileChooser by inheriting it and do whatever you want
-
JFileChooser causes "java.exe - Application Error"
Hi,
When I'm closing an JFileChooser dialog (by e.g. pressing ok or cancel) a second or so later my JVM terminates with the error message "java.exe - Application Error. The instruction at "0*6d0ea46e" referenced a memory at "0x00000000". The memory could not be "read". Click on OK to treminate the program".
I turned on verbose output from the JVM and the last printout was:
[Loaded javax.swing.Autoscroller from C:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar]
[Dynamic-linking native method sun.awt.windows.WComponentPeer.removeNativeDropTarget ... JNI]
result 1
[Dynamic-linking native method sun.awt.windows.WFramePeer.getState ... JNI]
[Loaded java.awt.EventDispatchThread$StopDispatchEvent from C:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar]
[Dynamic-linking native method sun.awt.windows.WToolkit.shutdown ... JNI]
No exception is shown.
I have uninstall all old JVMs and reinstalled JDK 5.0. This does not help.
This simple program causes the termination of the JVM:
public static void main(String[] args) {
System.out.println("0");
JFileChooser fileChooser = new JFileChooser();
System.out.println("1");
int result = -2;
try {
result = fileChooser.showOpenDialog(null);
} catch (HeadlessException e1) {
e1.printStackTrace();
System.out.println("result " + result);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("2");
I receive the printout "result" but not "2".
I appriciate any help!
BR
/MarcusNo, this is very bad. Any time you see a message like this mentioning a memory address, it means that java, not you, has crashed. There's no way for you to fix this. The only thing you can try is to work around it.
My suggestions:
1. Report it to Sun. Make sure you include your system info (processor, memory, computer manufacturer) and what version of java you're using
2. Try downloading and installing a different version of java -
JFileChooser disable acept button
Im using JFileChooser (a sub class of it actually) and have a situation where I must ensure that pick an existing file.
My thoughts were that I could either
1. not allow users to type their own file name into the file box
or
2. do not allow them to choose the accept button when the files does not exist.
Exploring these ideas:
for #1 you could change the text box to be read only (not accept typing) at all times
for #2 you would have to change the accept button to read only if the file did not exist
playing with # 2, I changed the propertyChange listener
if ("SelectedFileChangedProperty".equals(evt.getPropertyName())) {
if (!getSelectedFile().exists()) {
// this is where you would disable the button
}Does anyone have a clue how you would go about disabling either the accept button or the text field?thanks for the link.
I think I agree with some in that post that it might annoy users if the field was read only...
ok, after further exploration, here is my solution now:
override the default approveSelection method and check the file before processing...
public void approveSelection() {
if (!getSelectedFile().exists()) {
JOptionPane.showMessageDialog(this,getSelectedFile().getName() + " does not exist", "Info", JOptionPane.PLAIN_MESSAGE);
} else {
super.approveSelection();
} -
JFileChooser SaveDialog clears filename when you change extension
I created an instance of my GraphicFileChooser class which extends JFileChooser and named the instance chooser. I execute chooser.showSaveDialog(null); This brings up JFileChooser's save dialog. Everything works fine for the most part. I am able to save and cancel and change files and overwrite and everything. The one problem I have is that when I change the file extension type in the dropdown(i. jpg to png) the text box for the file name clears itself. I want the text box to always show what is typed in it and never clear. I have spent way to much time trying to work this minor detail out and would greatly appreciate it if somebody could help me. Thank you
Look these issues up in the Bug Database.
If you don't see them, have the Windows 2000 user post
a bug report explaining in detail the issue, so that
those wonderful people who work on such issues can
have the info available to resolve them.When I say post a bug report, I mean post the bug report **in the Bug Database**. Don't post them in the forums. -
Hang when using UIManager.getSystemLookAndFeelClassName() and JFileChooser
i encountered this wierd problem when i used UIManager.getSystemLookAndFeelClassName() and JFileChooser on a machine with win2002 (no service pack installed) and on another machine with winxp (no service pack installed). the code works perfectly fine with other pc but apparently our client did something to make it hang whenever either of these were called. i was just wondering how this can happen since its no longer a code problem but rather betwen java and windows. our program runs on java 1.4.x.
for more info about this problem here's a simple test program that doesnt work on the said machines:
=== code start ===
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
public class Test {
public static void main(String[] args) throws Exception {
// this portion works fine. this is to prove that there is no problem with IO on java
File file = new File(".");
String files[] = file.list();
System.out.println(file.getAbsolutePath());
for(int i=0;i<files.length;i++)
System.out.println(files);
// program hangs on this part. see thread dump of JFileChooser below
System.out.println("init JFileChooser");
JFileChooser fileChooser = new JFileChooser ();
// when code above is commented out, program also hangs on this part. see thread dump of UIManager below
System.out.println("init UILookAndFeel");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
System.out.println("done");
=== code end ===
thread dump of JFileChooser:
=== thead dump start ===
Full thread dump Java HotSpot(TM) Client VM (1.4.2_03-b02 mixed mode):
"AWT-Windows" daemon prio=7 tid=0x02e2ebb8 nid=0x93c runnable [70bf000..70bfd8c]
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(WToolkit.java:262)
at java.lang.Thread.run(Thread.java:534)
"Signal Dispatcher" daemon prio=10 tid=0x009c8da8 nid=0xa74 waiting on condition [0..0]
"Finalizer" daemon prio=9 tid=0x00990a10 nid=0x860 in Object.wait() [2b4f000..2b4fd8c]
at java.lang.Object.wait(Native Method)
- waiting on <0x105103a8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
- locked <0x105103a8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
"Reference Handler" daemon prio=10 tid=0x0098f5e0 nid=0xa6c in Object.wait() [2b0f000..2b0fd8c]
at java.lang.Object.wait(Native Method)
- waiting on <0x10510410> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:429)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
- locked <0x10510410> (a java.lang.ref.Reference$Lock)
"main" prio=5 tid=0x00034a88 nid=0xa64 runnable [7e000..7fc3c]
at sun.awt.font.NativeFontWrapper.registerFonts(Native Method)
- locked <0x14199820> (a java.lang.Class)
at sun.java2d.SunGraphicsEnvironment.addPathFonts(SunGraphicsEnvironment.java:797)
at sun.java2d.SunGraphicsEnvironment.registerFonts(SunGraphicsEnvironment.java:643)
at sun.java2d.SunGraphicsEnvironment.access$200(SunGraphicsEnvironment.java:53)
at sun.java2d.SunGraphicsEnvironment$2.run(SunGraphicsEnvironment.java:262)
at java.security.AccessController.doPrivileged(Native Method)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:256)
- locked <0x10510430> (a sun.awt.Win32GraphicsEnvironment)
at sun.java2d.SunGraphicsEnvironment.mapFontName(SunGraphicsEnvironment.java:504)
at java.awt.Font.initializeFont(Font.java:312)
at java.awt.Font.<init>(Font.java:344)
at sun.awt.windows.WDesktopProperties.setFontProperty(WDesktopProperties.java:157)
- locked <0x105367f8> (a sun.awt.windows.WDesktopProperties)
at sun.awt.windows.WDesktopProperties.getWindowsParameters(Native Method)
at sun.awt.windows.WDesktopProperties.<init>(WDesktopProperties.java:56)
at sun.awt.windows.WToolkit.initializeDesktopProperties(WToolkit.java:876)
at java.awt.Toolkit.getDesktopProperty(Toolkit.java:1569)
- locked <0x105367c0> (a sun.awt.windows.WToolkit)
at sun.awt.shell.ShellFolder.<clinit>(ShellFolder.java:208)
at javax.swing.filechooser.FileSystemView.getRoots(FileSystemView.java:335)
at javax.swing.filechooser.WindowsFileSystemView.getHomeDirectory(FileSystemView.java:649)
at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(MetalFileChooserUI.java:214)
at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:130)
at javax.swing.plaf.metal.MetalFileChooserUI.installUI(MetalFileChooserUI.java:152)
at javax.swing.JComponent.setUI(JComponent.java:449)
at javax.swing.JFileChooser.updateUI(JFileChooser.java:1701)
at javax.swing.JFileChooser.setup(JFileChooser.java:345)
at javax.swing.JFileChooser.<init>(JFileChooser.java:320)
at javax.swing.JFileChooser.<init>(JFileChooser.java:273)
at Test.main(Test.java:26)
"VM Thread" prio=5 tid=0x009c76e8 nid=0xa68 runnable
"VM Periodic Task Thread" prio=10 tid=0x009cb5c8 nid=0x9d0 waiting on condition
"Suspend Checker Thread" prio=10 tid=0x009c8460 nid=0xa70 runnable
=== thead dump ends ===
thread dump of UIManager:
=== thead dump start ===
Full thread dump Java HotSpot(TM) Client VM (1.4.2_03-b02 mixed mode):
"AWT-Windows" daemon prio=7 tid=0x02e29d88 nid=0x960 runnable [725f000..725fd8c]
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(WToolkit.java:262)
at java.lang.Thread.run(Thread.java:534)
"Signal Dispatcher" daemon prio=10 tid=0x009c8da8 nid=0x2a8 waiting on condition [0..0]
"Finalizer" daemon prio=9 tid=0x00990a10 nid=0x784 in Object.wait() [2b4f000..2b4fd8c]
at java.lang.Object.wait(Native Method)
- waiting on <0x1050f430> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
- locked <0x1050f430> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
"Reference Handler" daemon prio=10 tid=0x0098f5e0 nid=0x350 in Object.wait() [2b0f000..2b0fd8c]
at java.lang.Object.wait(Native Method)
- waiting on <0x1050f498> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:429)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
- locked <0x1050f498> (a java.lang.ref.Reference$Lock)
"main" prio=5 tid=0x00034a88 nid=0x934 runnable [7e000..7fc3c]
at sun.awt.font.NativeFontWrapper.registerFonts(Native Method)
- locked <0x141ed340> (a java.lang.Class)
at sun.java2d.SunGraphicsEnvironment.addPathFonts(SunGraphicsEnvironment.java:797)
at sun.java2d.SunGraphicsEnvironment.registerFonts(SunGraphicsEnvironment.java:643)
at sun.java2d.SunGraphicsEnvironment.access$200(SunGraphicsEnvironment.java:53)
at sun.java2d.SunGraphicsEnvironment$2.run(SunGraphicsEnvironment.java:262)
at java.security.AccessController.doPrivileged(Native Method)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:256)
- locked <0x1050f4a0> (a sun.awt.Win32GraphicsEnvironment)
at sun.java2d.SunGraphicsEnvironment.mapFontName(SunGraphicsEnvironment.java:504)
at java.awt.Font.initializeFont(Font.java:312)
at java.awt.Font.<init>(Font.java:344)
at sun.awt.windows.WDesktopProperties.setFontProperty(WDesktopProperties.java:157)
- locked <0x10534da8> (a sun.awt.windows.WDesktopProperties)
at sun.awt.windows.WDesktopProperties.getWindowsParameters(Native Method)
at sun.awt.windows.WDesktopProperties.<init>(WDesktopProperties.java:56)
at sun.awt.windows.WToolkit.initializeDesktopProperties(WToolkit.java:876)
at java.awt.Toolkit.getDesktopProperty(Toolkit.java:1569)
- locked <0x1050f268> (a sun.awt.windows.WToolkit)
at com.sun.java.swing.plaf.windows.XPStyle.getXP(XPStyle.java:75)
- locked <0x1427fd50> (a java.lang.Class)
at com.sun.java.swing.plaf.windows.WindowsTreeUI$ExpandedIcon.<init>(WindowsTreeUI.java:123)
at com.sun.java.swing.plaf.windows.WindowsTreeUI$ExpandedIcon.createExpandedIcon(WindowsTreeUI.java:127)
at com.sun.java.swing.plaf.windows.WindowsLookAndFeel.initComponentDefaults(WindowsLookAndFeel.java:309)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:81)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:394)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:424)
at Test.main(Test.java:23)
"VM Thread" prio=5 tid=0x009c76e8 nid=0x92c runnable
"VM Periodic Task Thread" prio=10 tid=0x009cb5c8 nid=0x944 waiting on condition
"Suspend Checker Thread" prio=10 tid=0x009c8460 nid=0x940 runnable
=== thead dump ends ===
hope someone can clarify me with this wierd anomaly.
thanks.
- ian
[email protected]Try to move the following line of ur code to the first statement in main()
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
Maybe you are looking for
-
Hi all, If u have different date fields in the cube delivery date actual delivery date goods issue date delivery at warehouse and they have taken as characterstics? how they should be mapped in cube?
-
SMP 3.0: how to handle header values in the SOAP WS using Integration Gateway
Hi Experts, We have a requirement from our current customer where they are providing us a SOAP WS.For one of the method we are passing "username" & "password" as input parameters and getting one security key (some unique number) in the response. We a
-
I am using an HP J4680 all-in one and windows 7. I'm not experiencing the problem with IE.
-
I recently transfered all my emails from Entourage to Mac Mail. Everything transfered beautifully. I had set up a tree of folders of all emails grouped in to specific topics in Entourage and they imported to mac mail in the same format. These emails
-
Packaging concept for GUI and Background, using SwingWorker
How to set up the following structure, in order to meet the requirements of SwingWorker (doInBackground, publish, process): 1. There is a class SGui - contained in a package of Swing GUI methods SGui, located in package ...sgui - which will - start a