jfilechooser

how to import datas from excel to jTable?

佐手、 提交于 2019-12-05 03:01:39
问题 JFileChooser fc = new JFileChooser(); int option = fc.showSaveDialog(NewJFrame1.this); if(option == JFileChooser.APPROVE_OPTION){ String filename = fc.getSelectedFile().getName(); String path = fc.getSelectedFile().getParentFile().getPath(); int len = filename.length(); String ext = ""; String file = ""; if(len > 4){ ext = filename.substring(len-4, len); } if(ext.equals(".xls")){ file = path + "\\" + filename; }else{ file = path + "\\" + filename + ".xls"; } toExcel(jTable1, new File(file));

Set locale properly to a JFileChooser

耗尽温柔 提交于 2019-12-05 01:58:02
问题 I'm having a little problem when I change Locale at runtime. The Goal I have to change the Locale of my application language according to a configuration file. This locale does not necessarily be the same of the host/OS locale nor the JVM default locale. Moreover, I can't modify user.language when I call the application. Then, I must do that at runtime. The Problem Summarizing my code, I read the configuration file and get the different options (including locale). After that, I initialize the

Open only .xml file in JFileChooser

孤者浪人 提交于 2019-12-05 00:35:50
问题 I am developing a java application for which I need only .xml files. Now I want to show only .xml files in JFileChooser whenever user wants to save a file or open a existing file. Is this possible to show only .xml files? 回答1: You can use JFileChooser API to achieve your task. For Open only .xml file // create a filechooser; JFileChooser chooser = new JFileChooser(cwd); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter( "xml files (*.xml)", "xml"); chooser.setDialogTitle("Open

Saving with a JFileChooser

為{幸葍}努か 提交于 2019-12-04 18:30:19
I am using a JFileChooser and the showSaveDialoge() and setSelectionMode(JfileChooser.DIRECTORIES_ONLY) to set where a preselected file will be saved and what it will be called. I want the user to be able to choose the name the new version, and where to put it. How do I go about this? I also wish to choose a default name. I hope the codes below implemented inline with your question requirements. The criteria in your question are answered in the code comment. If you need clarification, please let me know. import java.awt.BorderLayout; import java.awt.Insets; import java.awt.event.ActionEvent;

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

不打扰是莪最后的温柔 提交于 2019-12-04 18:09:35
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 answers to those questions seem overly complex, involving creating more GUI elements, which I can't believe

JFileChooser change default directory in Windows

妖精的绣舞 提交于 2019-12-04 17:20:34
问题 I want to change the default directory of my JFileChooser to "My Music" on Windows. This directory is C:\Users\Fre\Music on my account because my username is Fre The default is set on C:\Users\Fre\Documents (depends on OS i think). How can I change this? 回答1: You can use the API method setCurrentDirectory when initializing your JFileChooser objects: public void setCurrentDirectory(File dir) Sample usage might be like: yourFileChooser.setCurrentDirectory(new File (System.getProperty("user.home

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

南楼画角 提交于 2019-12-04 10:54:22
问题 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? 回答1: 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

Scrollbar in JFileChooser gives error

∥☆過路亽.° 提交于 2019-12-04 07:45:03
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 SwingTest extends JFrame { public SwingTest() { JButton button = new JButton("Choose files"); add

JFileChooser use within JApplet

筅森魡賤 提交于 2019-12-04 07:25:40
Can a JApplet use a JFileChooser so that the user can select a file on his hard-drive? Or would this violate Java applet security? (I'm assuming that the default security settings are being used. I don't want to ask my users to grant me extra permissions.) This thread indicates that you need to digitally sign your applet before a JFileChooser is permitted. As mentioned, you need to sign your applet, which result in a "vague security warning" when the user is presented the applet. When the user accept to run this applet, the applet is given full access and functions like an ordinary application

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

馋奶兔 提交于 2019-12-04 05:15:16
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 don't feel it should be enforced. So, is there any way I could achieve this? The API does not offer that