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
listview javafx
add a comment |
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
listview javafx
This line can be improved:s = ""+file.getAbsolutePath()just writes = file.getAbsolutePath(). What's wrong with using aListViewto show the list of files? What have you tried and what problem do you have with this approach?
– Gnas
Nov 19 at 12:12
You appear to want to usetesteas an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass ofjavafx.event.Eventor no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
– Slaw
Nov 19 at 12:39
add a comment |
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
listview javafx
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
listview javafx
edited Nov 19 at 11:42
Slaw
5,7482829
5,7482829
asked Nov 19 at 10:58
Bunnytheh0tbeast
41
41
This line can be improved:s = ""+file.getAbsolutePath()just writes = file.getAbsolutePath(). What's wrong with using aListViewto show the list of files? What have you tried and what problem do you have with this approach?
– Gnas
Nov 19 at 12:12
You appear to want to usetesteas an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass ofjavafx.event.Eventor no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
– Slaw
Nov 19 at 12:39
add a comment |
This line can be improved:s = ""+file.getAbsolutePath()just writes = file.getAbsolutePath(). What's wrong with using aListViewto show the list of files? What have you tried and what problem do you have with this approach?
– Gnas
Nov 19 at 12:12
You appear to want to usetesteas an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass ofjavafx.event.Eventor no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
– Slaw
Nov 19 at 12:39
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 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 at 12:12
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
Nov 19 at 12:39
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
Nov 19 at 12:39
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
This line can be improved:
s = ""+file.getAbsolutePath()just writes = file.getAbsolutePath(). What's wrong with using aListViewto show the list of files? What have you tried and what problem do you have with this approach?– Gnas
Nov 19 at 12:12
You appear to want to use
testeas an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass ofjavafx.event.Eventor no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.– Slaw
Nov 19 at 12:39