jfilechooser

How to change default java icon in JFileChooser

天涯浪子 提交于 2019-12-10 20:48:08
问题 I want to change the inbuilt java icon from JFileChooser . JFrame class has a setIconImage() method for set icon.But I couldn't find anything like that for JFileChooser . Without changing that coffee cup anyone can easily recognize that my software is made with java. Can anyone can help me to avoid this? 回答1: IIRC the icon for the JFileChooser is taken from the jFrame that is passed in. By changing the icon for the JFrame, you should also get the reflected icon change in the JFileChooser. the

How to copy an image in JTextPane java?

蹲街弑〆低调 提交于 2019-12-10 18:26:46
问题 I want to know how to copy an image and text in JTextPane. When I use this code, it copies just text but I want to copy text and image. How can be done this? import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.*; /** * *

Localizing the JFileChooser “All Files” string

ぐ巨炮叔叔 提交于 2019-12-10 14:31:16
问题 I am working on a java application with a JFileChooser and the user is able to switch languages. Locale.setDefault( Locale.ENGLISH ); JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog( null ); Locale.setDefault( Locale.CHINA ); JFileChooser.setDefaultLocale( Locale.CHINA ); JFileChooser chinese_chooser = new JFileChooser(); chinese_chooser.showOpenDialog( null ); The second file chooser to appear is in Chinese except for the "All Files" string in the drop down box. If I

How to save a txt file using JFileChooser?

▼魔方 西西 提交于 2019-12-10 11:45:42
问题 Given this method : public void OutputWrite (BigInteger[] EncryptCodes) throws FileNotFoundException{ JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.showSaveDialog(null); String path = chooser.getSelectedFile().getAbsolutePath(); PrintWriter file = new PrintWriter(new File(path+"EncryptedMessage.txt")); for (int i = 0; i <EncryptCodes.length; i++) { file.write(EncryptCodes[i]+ " \r\n"); } file.close(); } Ignoring the variable

How to get directory path using JFileChooser?

好久不见. 提交于 2019-12-10 02:33:43
问题 I have a small java GUI application with a text field on it. When the user clicks the text field an event is triggered and the JFileChooser is launched. It's restricted to directories only. What I'm trying to do is to get the full path of the directory that was chosen and put it in the text field. I have no idea how to do this, I've searched through a ton of java tutorials and documentations and I can't find an answer. Can someone help me? To clarify: I want to get the full path as a string

Saving with a JFileChooser

こ雲淡風輕ζ 提交于 2019-12-09 23:25:21
问题 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. 回答1: 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,

jfilechooser - set directory to a path in a file

ぃ、小莉子 提交于 2019-12-09 14:47:39
问题 I am trying to set the directory path in JFilechooser through something like this(using commons-io ) : String fileContents = IOUtils.toString(new FileInputStream("path.txt")); File theDirectory = new File(fileContents); filechooser = new JFileChooser(); fileChooser.setCurrentDirectory(theDirectory); filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); I'm using getCanonicalPath() to get the path and write in the file path.txt path = file.getCanonicalPath(); I don't intend to put

How to restrict file choosers in java to specific files

≯℡__Kan透↙ 提交于 2019-12-09 14:38:23
问题 private void openMenuActionPerformed(java.awt.event.ActionEvent evt) { DBmanager db = new DBmanager(); if (!db.getCurrentUser().equals("Admin")) { JOptionPane.showMessageDialog(this, "You are Not Allowed to Run Applications"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Documents", "pdf")); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("MS Office

JFileChooser from a command line program and popping up Underneath all windows

穿精又带淫゛_ 提交于 2019-12-09 10:13:50
问题 Ive implemented the jFileChooser in my command line program and it works, just as it should with only one annoying issue. It seems that it opens underneath every window with no alert of any kind. In fact I even missed it a couple of times at first leading me to believe that i had implemented it wrong. I have implemented this as follows: System.out.println("Please select the file"); JFileChooser fc = new JFileChooser(); int retValue = fc.showOpenDialog(new JPanel()); if(retValue ==

Set default saving extension with JFileChooser

房东的猫 提交于 2019-12-09 08:20:24
问题 I'm trying to save a file using JFileChooser . However, I seem to be having some trouble with it. Here's my code: if (e.getSource() == saveMenu) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); FileNameExtensionFilter xmlFilter = new FileNameExtensionFilter("xml files (*.xml)", "xml"); // add filters chooser.addChoosableFileFilter(xmlFilter); chooser.setFileFilter(xmlFilter); int result = chooser.showSaveDialog(Simulation.this); if