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











up vote
0
down vote

favorite












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









New contributor




Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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
    2 days ago












  • You appear to want to use teste as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass of javafx.event.Event or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
    – Slaw
    2 days ago

















up vote
0
down vote

favorite












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









New contributor




Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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
    2 days ago












  • You appear to want to use teste as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass of javafx.event.Event or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
    – Slaw
    2 days ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











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









New contributor




Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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









New contributor




Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Slaw

5,5932729




5,5932729






New contributor




Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Bunnytheh0tbeast

41




41




New contributor




Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Bunnytheh0tbeast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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
    2 days ago












  • You appear to want to use teste as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass of javafx.event.Event or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
    – Slaw
    2 days ago




















  • 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
    2 days ago












  • You appear to want to use teste as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass of javafx.event.Event or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
    – Slaw
    2 days ago


















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
2 days ago






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
2 days ago














You appear to want to use teste as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass of javafx.event.Event or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
– Slaw
2 days ago






You appear to want to use teste as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass of javafx.event.Event or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
– Slaw
2 days ago



















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',
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
});


}
});






Bunnytheh0tbeast is a new contributor. Be nice, and check out our Code of Conduct.










 

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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Bunnytheh0tbeast is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Bunnytheh0tbeast is a new contributor. Be nice, and check out our Code of Conduct.













Bunnytheh0tbeast is a new contributor. Be nice, and check out our Code of Conduct.












Bunnytheh0tbeast is a new contributor. Be nice, and check out our Code of Conduct.















 


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

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

WPF add header to Image with URL pettitions [duplicate]