jfilechooser

How can Swing dialogs even work?

有些话、适合烂在心里 提交于 2019-12-03 15:23:17
问题 If you open a dialog in Swing, for example a JFileChooser, it goes somewhat like this pseudocode: swing event thread { create dialog add listener to dialog close event { returnValue = somethingFromDialog } show dialog (wait until it is closed) return returnValue } My question is: how can this possibly work? As you can see the thread waits to return until the dialog is closed. This means the Swing event thread is blocked. Yet, one can interact with the dialog, which AFAIK requires this thread

JFileChooser for directories on the Mac: how to make it not suck?

試著忘記壹切 提交于 2019-12-03 07:03:48
The JFileChooser in "directories only" mode on the Mac has two serious, crippling problems: 1) You cannot create directories with it 2) You cannot switch drives This is rather a huge problem for my installer app. As far as I can tell, Apple provides no way around this problem, you can't even activate the non-native directory chooser ... so the only alternative is to find a free/open source pure-Java replacement widget. Does anybody know of one? What about using java.awt.FileDialog? It shows a native file chooser and allows creating new folders. public static void main(String[] args) throws

System look and feel layout on JFileChooser but with nimbus look and feel theme

谁说我不能喝 提交于 2019-12-03 07:02:16
The windows look and feel layout on JFileChooser is much better than other look and feels like nimbus. So I'm looking for a way to have the layout of a system look and feel but have nimbus or others theme on top. Is this possible? If so how can it be done? It's possible, though I don't know whether it's recommended. I managed to get it to work by asking the view to update itself on all but the topmost JFileChooser component (since that would replace all the chooser components with the Nimbus ones which you don't want). I'd regard this as a hack that may or may not work depending on the

Browse for folder dialog

流过昼夜 提交于 2019-12-03 06:36:32
问题 I need to know how to get the "browse for folder" dialog in java. I am aware of SWT. But I need to do in swing? Is there any solution to this? [As we start on eclipse it will ask for choose workspace. We can see the browse for folder dialog at that time] Thanks in advance. 回答1: Sounds like you'll want to use a JFileChooser. Oracle has a bunch of tutorials on basic Swing components and how to use them. Here's their tutorial page for the JFileChooser: link. 回答2: You can force JFileChooser to

How can Swing dialogs even work?

此生再无相见时 提交于 2019-12-03 04:58:51
If you open a dialog in Swing, for example a JFileChooser, it goes somewhat like this pseudocode: swing event thread { create dialog add listener to dialog close event { returnValue = somethingFromDialog } show dialog (wait until it is closed) return returnValue } My question is: how can this possibly work? As you can see the thread waits to return until the dialog is closed. This means the Swing event thread is blocked. Yet, one can interact with the dialog, which AFAIK requires this thread to run. So how does that work? It's the AWT's thread, not Swing's. Anyway, AWT runs the dispatch loop

Browse for folder dialog

社会主义新天地 提交于 2019-12-02 20:15:35
I need to know how to get the "browse for folder" dialog in java. I am aware of SWT. But I need to do in swing? Is there any solution to this? [As we start on eclipse it will ask for choose workspace. We can see the browse for folder dialog at that time] Thanks in advance. Sounds like you'll want to use a JFileChooser . Oracle has a bunch of tutorials on basic Swing components and how to use them. Here's their tutorial page for the JFileChooser: link . You can force JFileChooser to select only folders, if you add the following command. _fileChooser.setFileSelectionMode( JFileChooser

Reading the java files from the folder

痞子三分冷 提交于 2019-12-02 17:10:47
问题 I have developed an application that reads files from the folder chosen by the user. It displays how many lines of code are in each file. I want only Java files to be shown in the file-chooser (files having .java extension). Below is my code: public static void main(String[] args) throws FileNotFoundException { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File("C:" + File.separator)); chooser.setDialogTitle("FILES ALONG WITH LINE NUMBERS"); chooser

Panel losing color

给你一囗甜甜゛ 提交于 2019-12-02 12:59:28
When I click on the button that activates the file chooser, and add the resulting file the panel color disappears. Does anyone know why this is happening? import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.filechooser.FileSystemView; import javax.swing.JFileChooser; import javax.swing.plaf.FileChooserUI;

JFileChooser on Mac cannot see files named by Chinese chars?

大憨熊 提交于 2019-12-02 12:34:54
问题 The program worked fine when running in Intellij (it can see the Chinese named files). I built it into a .jar file. Executed the jar and the JFileChooser cannot see those files. And I tried the jar in Windows, it works completely fine. 回答1: This works file for me on Mac OS X 10.8.2: import java.io.File; import javax.swing.JFileChooser; public class JFileChooserTest { public static void main(String[] args) { System.out.println("file.encoding=" + System.getProperty("file.encoding")); String

Starting a JFileChooser at a specified directory and only showing files of a specific type

元气小坏坏 提交于 2019-12-02 10:24:50
I have a program utilizing a JFileChooser. To be brief, the full program is a GUI which allows users to manipulate PNGs and JPGs. I would like to make it so that the JFileChooser instantly opens to the picture directory (windows). When the user opens their JFileChooser, it would open directly to the pictures library C:\Users\(USER)\Pictures Furthermore, it would be nice to ONLY show files of a specific type (PNGs and JPGs). Many programs seem to be able to do this; only allowing selection of specific files. Does JFileChooser allow such a thing? Currently, I am using a massively unreliable, run