jfilechooser

error message with JButton and JFileChooser

隐身守侯 提交于 2019-12-13 08:26:27
问题 I want to have a button with a JFileChooser action. This is the code that I wrote: public class Main { private static String fullPath; private JFileChooser inputFile; public static void main(String args[]) throws FileNotFoundException, IOException { try { GridBagConstraints gbc = new GridBagConstraints(); JButton inputButton = new JButton("Browse input file"); myPanel.add(inputButton, gbc); inputButton.addActionListener(new ActionListener() { public void ActionPerformed(ActionEvent e) {

change look and feel of JFileChooser in swing

非 Y 不嫁゛ 提交于 2019-12-13 05:20:45
问题 My requirement is to add check box with every directory which is shown by JFileChooser. and give multi selection facility. How can I achieve this? 回答1: It would probably be easier to implement a custom component than alter a JFileChooser to support this (odd) requirement. You might start with altering the component used in File Manager questions. 回答2: JFileChooser has multi-selection built in (setMultiSelectionEnabled()). It doesn't use checkboxes, but you can select multiple items. 回答3: I

Java - Extremely basic JFileChooser issue

☆樱花仙子☆ 提交于 2019-12-13 04:17:54
问题 I'd like to make a JFileChooser that lets the user select any file OR directory that contains the word "hello". That is, the following are valid selections: C:\hello\ C:\fun\hello.txt etc. How can i get this working? I've tried: import java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; JFileChooser f = new JFileChooser(); f.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); f.setFileFilter(new FileFilter() { public boolean accept(File file) {

Can a user-chosen image be inserted directly into a JEditorPane?

我的未来我决定 提交于 2019-12-13 03:46:59
问题 What I am trying to do is open up a JFilechooser that filters jpeg,gif and png images, then gets the user's selection and inserts it into the JEditorPane. Can this be done? or am i attempting something impossible? Here is a sample of my program.(insert is a JMenuItem and mainText is a JEditorPane) insert.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ JFileChooser imageChooser = new JFileChooser(); imageChooser.setFileFilter(new FileNameExtensionFilter(

JFileChooser: set the name text field not enabled

大城市里の小女人 提交于 2019-12-13 02:57:53
问题 I'm using a JFileChooser to let the user save a file. But I don't want the user to choose a name, for the file to save. The name text field must be not enabled. I read the doc and I did not find a such method or property. 回答1: Squiddie in comments recommends you a good solution. However if still want to disable the textfield, so the name of the file is visible to the user (with JFileChooser.DIRECTORIES_ONLY it is not ), you can use the following code in order to "grab" the textfield from the

JavaVM Windows 7 64bit - JFileChooser() not showing dialog box

折月煮酒 提交于 2019-12-13 00:32:00
问题 I am trying to create a simple console based java application, which requires users to select files from their local filesystem. The console prompts the user to select one of the available options and then switches on the input given. public Client() throws UnknownHostException, IOException { printuseroptions(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char userdecision = br.readLine().charAt(0); System.out.println(userdecision); switch(userdecision){ case '1'

how to upload and display image in JFrame using JFileChooser

試著忘記壹切 提交于 2019-12-12 14:27:44
问题 I need to upload and display an image selected with the JFileChooser (i.e the user wants to set his/her profile picture) in a JFrame .. How should I do it? Here is my code for choosing the file: private void UploadImageActionPerformed(java.awt.event.ActionEvent evt) { int returnVal = fileChosser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChosser.getSelectedFile(); // What to do with the file // I want code for this part try { //code that might create

JFileChooser is not opening default Win 7 File Explorer [duplicate]

牧云@^-^@ 提交于 2019-12-12 13:58:18
问题 This question already has answers here : Does Swing support Windows 7-style file choosers? (10 answers) Closed 4 years ago . I am using JFileChooser to open the File Explorer in WIN 7 and realized that its opening the old UI , but same SWT FileDialog is opening the WIN 7 File Explorer only. Is there any specific reason. JFileChooser : SWT FileDialog : 回答1: AFAIK this not possible for AWT / Swing, Java 6 / 7 missed that, some implementetion as for WinXP (maybe for Vista too, never used this

JFileChooser on a Button Click

旧城冷巷雨未停 提交于 2019-12-12 13:16:00
问题 I have a button, clicking on which I want the JFileChooser to pop up. I have tried this JButton browse= new JButton("Browse"); add(browse); browse.addActionListener(new ClassBrowse()); public class ClassBrowse implements ActionListener { public void actionPerformed(ActionEvent e) { int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { // return the file path } catch (Exception ex) { System.out.println

How does JFileChooser return the exit value?

北慕城南 提交于 2019-12-12 09:55:32
问题 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