Javafx how to show files of a directory using a button before to choose it












0















Guys i don't know how to show all the files in a certain directory on a listview. I thought in using a arraylist shown on other post here but it didnt helped because i have a button to find and choose a directory and then a listview that was suposed to show us all the files inside that directory this is my code maybe is a silly question maybe is not but i need help really fast



public class FXMLDocumentController implements Initializable {

@FXML
private Label label;
@FXML
private TextField textfield;
@FXML
private AnchorPane anchorid;
@FXML
private ListView listOfFiles;

@FXML
private String handleButtonAction(ActionEvent event) {

final DirectoryChooser dirchooser = new DirectoryChooser();
Stage stage = (Stage) anchorid.getScene().getWindow();
File file = dirchooser.showDialog(null);
String s = "";
if (file != null) {
System.out.println("Path: " + file.getAbsolutePath());
s = ""+file.getAbsolutePath();
textfield.setText(file.getAbsolutePath());
}
return s;
}

@FXML
private void teste(ActionEvent event, String s) {
File folder = new File(s);
File listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}

@Override
public void initialize(URL url, ResourceBundle rb) {
//Empty
}
}


EDIT: btw i forgot to say that that string s is just return something to get grabbed after in the other method to the listview










share|improve this question

























  • This line can be improved: s = ""+file.getAbsolutePath() just write s = file.getAbsolutePath(). What's wrong with using a ListView to show the list of files? What have you tried and what problem do you have with this approach?

    – Gnas
    Nov 19 '18 at 12:12


















0















Guys i don't know how to show all the files in a certain directory on a listview. I thought in using a arraylist shown on other post here but it didnt helped because i have a button to find and choose a directory and then a listview that was suposed to show us all the files inside that directory this is my code maybe is a silly question maybe is not but i need help really fast



public class FXMLDocumentController implements Initializable {

@FXML
private Label label;
@FXML
private TextField textfield;
@FXML
private AnchorPane anchorid;
@FXML
private ListView listOfFiles;

@FXML
private String handleButtonAction(ActionEvent event) {

final DirectoryChooser dirchooser = new DirectoryChooser();
Stage stage = (Stage) anchorid.getScene().getWindow();
File file = dirchooser.showDialog(null);
String s = "";
if (file != null) {
System.out.println("Path: " + file.getAbsolutePath());
s = ""+file.getAbsolutePath();
textfield.setText(file.getAbsolutePath());
}
return s;
}

@FXML
private void teste(ActionEvent event, String s) {
File folder = new File(s);
File listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}

@Override
public void initialize(URL url, ResourceBundle rb) {
//Empty
}
}


EDIT: btw i forgot to say that that string s is just return something to get grabbed after in the other method to the listview










share|improve this question

























  • This line can be improved: s = ""+file.getAbsolutePath() just write s = file.getAbsolutePath(). What's wrong with using a ListView to show the list of files? What have you tried and what problem do you have with this approach?

    – Gnas
    Nov 19 '18 at 12:12
















0












0








0








Guys i don't know how to show all the files in a certain directory on a listview. I thought in using a arraylist shown on other post here but it didnt helped because i have a button to find and choose a directory and then a listview that was suposed to show us all the files inside that directory this is my code maybe is a silly question maybe is not but i need help really fast



public class FXMLDocumentController implements Initializable {

@FXML
private Label label;
@FXML
private TextField textfield;
@FXML
private AnchorPane anchorid;
@FXML
private ListView listOfFiles;

@FXML
private String handleButtonAction(ActionEvent event) {

final DirectoryChooser dirchooser = new DirectoryChooser();
Stage stage = (Stage) anchorid.getScene().getWindow();
File file = dirchooser.showDialog(null);
String s = "";
if (file != null) {
System.out.println("Path: " + file.getAbsolutePath());
s = ""+file.getAbsolutePath();
textfield.setText(file.getAbsolutePath());
}
return s;
}

@FXML
private void teste(ActionEvent event, String s) {
File folder = new File(s);
File listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}

@Override
public void initialize(URL url, ResourceBundle rb) {
//Empty
}
}


EDIT: btw i forgot to say that that string s is just return something to get grabbed after in the other method to the listview










share|improve this question
















Guys i don't know how to show all the files in a certain directory on a listview. I thought in using a arraylist shown on other post here but it didnt helped because i have a button to find and choose a directory and then a listview that was suposed to show us all the files inside that directory this is my code maybe is a silly question maybe is not but i need help really fast



public class FXMLDocumentController implements Initializable {

@FXML
private Label label;
@FXML
private TextField textfield;
@FXML
private AnchorPane anchorid;
@FXML
private ListView listOfFiles;

@FXML
private String handleButtonAction(ActionEvent event) {

final DirectoryChooser dirchooser = new DirectoryChooser();
Stage stage = (Stage) anchorid.getScene().getWindow();
File file = dirchooser.showDialog(null);
String s = "";
if (file != null) {
System.out.println("Path: " + file.getAbsolutePath());
s = ""+file.getAbsolutePath();
textfield.setText(file.getAbsolutePath());
}
return s;
}

@FXML
private void teste(ActionEvent event, String s) {
File folder = new File(s);
File listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}

@Override
public void initialize(URL url, ResourceBundle rb) {
//Empty
}
}


EDIT: btw i forgot to say that that string s is just return something to get grabbed after in the other method to the listview







listview javafx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 11:42









Slaw

7,5083932




7,5083932










asked Nov 19 '18 at 10:58









Bunnytheh0tbeastBunnytheh0tbeast

41




41













  • This line can be improved: s = ""+file.getAbsolutePath() just write s = file.getAbsolutePath(). What's wrong with using a ListView to show the list of files? What have you tried and what problem do you have with this approach?

    – Gnas
    Nov 19 '18 at 12:12





















  • This line can be improved: s = ""+file.getAbsolutePath() just write s = file.getAbsolutePath(). What's wrong with using a ListView to show the list of files? What have you tried and what problem do you have with this approach?

    – Gnas
    Nov 19 '18 at 12:12



















This line can be improved: s = ""+file.getAbsolutePath() just write s = file.getAbsolutePath(). What's wrong with using a ListView to show the list of files? What have you tried and what problem do you have with this approach?

– Gnas
Nov 19 '18 at 12:12







This line can be improved: s = ""+file.getAbsolutePath() just write s = file.getAbsolutePath(). What's wrong with using a ListView to show the list of files? What have you tried and what problem do you have with this approach?

– Gnas
Nov 19 '18 at 12:12














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373162%2fjavafx-how-to-show-files-of-a-directory-using-a-button-before-to-choose-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373162%2fjavafx-how-to-show-files-of-a-directory-using-a-button-before-to-choose-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents