This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
I need to display the file name without the extension in JFileChooser(open mode). How?
Can anyone tell me how switch off extensions in view openDialog ?
I want see only name file without his extension in this view.
thanks
you can use a custom writen javax.swing.filechooser.FileView that you set in your filechooser
The Customizing the File View section in the Java Tutorial includes an example of defining your own FileView object to control how the files are displayed in a JFileChooser.
http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html
Override the FileView.getName() method to display a customized name for each file.
Download the FileChooserDemo2 demo from this web page to try the example and change method ImageFileView.getName() to return the filename with the file extension removed.
Related
This question already has answers here:
Environment.getExternalStorageDirectory() deprecated in API level 29 java
(13 answers)
Closed 1 year ago.
The method getExternalStoragePublicDirectory() is deprecated in Android Q. Now how to save and read a file? A file may be a txt file, pdf, mht format file etc, but it would not be an image.
As there is also a way to save a file using Storage Access Framework, but it is not fulfilling my requirement as it allow user to save file where they want to save it, but I want to save a file in a specific directory as we were doing through getExternalStoragePublicDirectory() and then also display all the saved files within a list.
In Android 10, You can use Scope Storage for store/read file. For Scope Storage, No Need to ask any permission also.
If you want to store your files externally means then you can use Media Store Api to access like activity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
Ref
use this code to get/create a directory, maybe it helps you
val dirc = File(
context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
.toString() + "/your_folder/"
)
if (!dirc.exists()) {
dirc.mkdir()
}
You can use MediaStore API for Saving files in android Q.
val values = ContentValues().apply{
put(MediaStore.Images.Media.RELATIVE_PATH,"MyPics")
In this RELATIVE_PATH is used for the custom path.
Android 10 Storage system
This question already has answers here:
How do I programmatically change file permissions?
(12 answers)
Closed 3 years ago.
I'm using the following Java code to create a file inside several folders:
Path pathOut = Paths.get("./", year, month, day, processId, "METADATA.txt");
File fileOut = pathOut.toFile();
boolean f = fileOut.getParentFile().mkdirs();
It works perfectly, but I'd need to set the permissions for each subfolder to '777'. Is it possible using mkdirs method or do I need to change the logic and use another approach?
Thanks!
Permission 777 is the same as rwxrwxrwx. Thus, you can set the required permission as follows:
Files.setPosixFilePermissions(path, PosixFilePermissions.fromString("rwxrwxrwx"))
This question already has answers here:
How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?
(14 answers)
Closed 4 years ago.
How to get a full native path of the file in String format which is being uploaded using and being used in a manged bean for its validation and upload? I also don't really want to use simple mode for p:fileUpload.
For example, if a file is being uploaded is from desktop then I want the path of the file as "C:\Users\\Desktop\" in a String format.
Any help would be really appreciated...
you can use java.nio.file.Path library
Path path = Paths.get("test.txt");
log("Path: " + path);
log("Absolute: " + path.isAbsolute());
This question already has answers here:
JFileChooser, want to lock it to one directory
(3 answers)
Closed 9 years ago.
I have a JFileChooser that opens in a specific directory and then allows the user to choose a directory within it (when selected w/ single-click and the OK button is pressed).
However, when the directory is double-clicked, the file chooser opens that directory instead of choosing it.
How can I either
override the double-click to choose the directory
disable navigation outside of the initial directory
disable double-clicking?
I've tried overriding the isTraversable() method in FileView and FileSystemView which works to restrict the file chooser to a directory, however, it then does not show any items inside of said directory.
Here's the code I have right now:
JFileChooser fc = new JFileChooser(dir);
fc.setApproveButtonText("OK");
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.showOpenDialog(fileChooserDialog);
File file = fc.getSelectedFile();
if (file.getParent().equals(dir)) {
//do something
}
You could modify the action map. I don't have a access to a compiler ATM so I can't test this out, but it should work .
JFileChooser chooser = new JFileChooser(".");
ActionMap am = chooser.getActionMap();
Action key = am.get("WHATEVER_THEACTIONAME_FOR_OPEN-DIR._IS") //I think it's "Open Folder";
key.setEnabled(false);
I will update this answer later when I have time and access to a compiler.
This question already has answers here:
JasperViewer - How to set file name and set the extension (format)?
(2 answers)
Closed 6 years ago.
I am creating Java desktop application. I am using DynamicReports API to create report.
The report was viewed in a JasperViewer. When I click save button, I want to display a name for report to save by default. How to set name for the report by default?
it is necessary to import the package com.jasperassistant.designer.viewer.ViewerComposite
so on that viewer composite you can see a save icon on you left top corner. you can provide any name and location where you want to save. i think that the good way of saving report through your jasper report.
Then i think that you have to change in JFileChooser instead of looking into API.
You can give default name to be displayed.
This way the approach would be:
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setSelectedFile(new File("fileToSave.txt"));
jFileChooser.showSaveDialog(parent);
And If you pass a File with an absolute path, JFileChooser will try to position itself in that directory (if it exists).
I got this source from following place