jfilechooser

How to generate a stand-alone JFileChooser dialog box on top of other windows?

雨燕双飞 提交于 2019-12-06 10:25:26
问题 Like some other people who have asked similar questions, I was going nuts trying to 'fix' my JFileChooser dialog box generation code until I noticed that it is being generated, but it is appearing underneath all other windows and does not have an associated taskbar icon (so there was no clue at all that it existed!). I am aware of these similar questions: Bringing JFileChooser on top of all windows JFileChooser from a command line program and popping up Underneath all windows ...but the

How does JFileChooser return the exit value?

久未见 提交于 2019-12-06 09:34:14
A typical way to use JFileChooser includes checking whether user clicked OK, like in this code: private void addModelButtonMouseClicked(java.awt.event.MouseEvent evt) { JFileChooser modelChooser = new JFileChooser(); if(modelChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ){ File selectedFile = modelChooser.getSelectedFile(); if(verifyModelFile(selectedFile)){ MetModel newModel; newModel = parser.parse(selectedFile, editedCollection.getDirectory() ); this.editedCollection.addModel(newModel); this.modelListUpdate(); } } } I tried to mimic this behavior in my own window inheriting

How do I add a file browser inside my Java application?

五迷三道 提交于 2019-12-06 04:43:22
问题 I am new to Java progamming and am building a application that will add, display and remove files from a given folder location. I have added files using JFileChooser and know how to delete the files. However I am stuck with the display portion. I want to display the files and folder using different icon inside my application. I tried to add a JFileChooser inside the display panel and disable the button and menu components of the dialog box, but I have not succeeded. Is there any better way to

Scrollbar in JFileChooser gives error

社会主义新天地 提交于 2019-12-06 03:22:04
问题 When I use JFileChooser, the first time I use its scrollbar, I get two or four copies of the following error message: 2016-01-08 18:37:17.706 java[14158:2289154] inOptions: { JavaCUIThumbStartKey = 0; "is.flipped" = 0; kCUIOrientationKey = kCUIOrientVertical; kCUIThumbProportionKey = "0.497863233089447"; max = 0; pressedpart = 0; state = normal; value = 0; widget = scrollbar; Here is sample code that has this behavior: package tests; import java.awt.event.*; import javax.swing.*; public class

Making a JFileChooser select the text of the file name but not the extension

谁说胖子不能爱 提交于 2019-12-05 23:10:00
问题 I'd like the text in the file name field of the JFileChooser save dialog to select just the file name and not the extension. I currently have this: And want it to look like this: This is a simple change, but one that makes saving a file much easier, in my opinion, since the user can start typing the file name right away without erasing the extension accidentally. I know I can forcefully add the extension if it's missing, but I'd rather not do this because the extension isn't mandatory and I

JFileChooser vs JDialog vs FileDialog

倖福魔咒の 提交于 2019-12-05 19:50:36
I need to know which of the 3 is best for me. My requirements are as follows in order of importance: Save and load files with ease. File type filter during file selection (not afterwards). Look and feel is exactly the same as the native OS L&F. If there is a dialog that I've not mentioned that would be more ideal, please let me know. What is the rest of your application written in? If you used AWT you should use FileDialog . If you used Swing you should use JFileChooser . Both classes meet all of your requirements. (A JDialog is simply an empty window, you can only use it to open files if you

How to get open file popup

大兔子大兔子 提交于 2019-12-05 16:47:41
Right now, I have a set class path, but I want to have an open file pop up and the user chooses which file to open. I've tried JFileChooser, but haven't been successful so far. Here's my code: public static void main(String[] args) throws IOException { JFileChooser chooser = new JFileChooser(); int returnValue = chooser.showOpenDialog( null ) ; if( returnValue == JFileChooser.APPROVE_OPTION ) { File file = chooser.getSelectedFile() ; } // I don't want this to be hard-coded: String filePath = "/Users/Bill/Desktop/hello.txt"; How should I go about doing this? I think the problem is the scope of

Start a JFileChooser with files ordered by date

做~自己de王妃 提交于 2019-12-05 13:08:20
A recent question asked: How can I start the JFileChooser in the Details view? and the answer provided a nice technique for doing that. I'd like to raise the aspiration here one level: given that I now know how to open the JFileChooser in details view, can I also get it to open with the files ordered by date? I know the user can of course click on the headings, but is there a way to make this happen in the code? I don't know of any API to do this. The following code finds the table used by the file chooser and then manually does the sort on the date column: JFrame frame = new JFrame();

Is there a bug setting title using JFileChooser.showDialog(Component, String) in Mac OS X?

大城市里の小女人 提交于 2019-12-05 12:25:24
Search doesn't turn anything up for this problem. I'm using simple code to display a JFileChooser dialog with customized title and accept button: JFileChooser fc = new JFileChooser(); fc.showDialog(null,"MyText"); On Windows 7 this works as expected: a Save Dialog is displayed, with "Save" replaced by "MyText" on the Accept button and dialog title. However, on Mac OS X, only the Accept button text is changed - the dialog title is blank. I'm using Java SE 7 and MacOS 10.8.5. By inserting this line between the two above: fc.setDialogTitle("MyText"); The correct title is displayed. Is this a

improving JFileChooser under Ubuntu 12.04 (GTK)

余生长醉 提交于 2019-12-05 11:05:45
I have a problem with the JFileChooser under Ubuntu 12.04. I use this code to set the look and feel: javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); And it looks like this. It's very uncomfortable to use and it looks very ugly: http://www9.picfront.org/token/9sRH/2012/05/15/2062476.jpg I would like it to look like this: http://www4.picfront.org/token/1lpa/2012/05/15/2062477.jpg Using the hint from this post , I tried to use FileDialog instead of the FileChooser . But FileDialog throws an exception when i start it in LOAD mode and click on the "open"