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
New contributor
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
New contributor
This line can be improved:s = ""+file.getAbsolutePath()
just writes = file.getAbsolutePath()
. What's wrong with using aListView
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 useteste
as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass ofjavafx.event.Event
or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
– Slaw
2 days ago
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
New contributor
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
New contributor
New contributor
edited 2 days ago
Slaw
5,5932729
5,5932729
New contributor
asked 2 days ago
Bunnytheh0tbeast
41
41
New contributor
New contributor
This line can be improved:s = ""+file.getAbsolutePath()
just writes = file.getAbsolutePath()
. What's wrong with using aListView
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 useteste
as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass ofjavafx.event.Event
or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.
– Slaw
2 days ago
add a comment |
This line can be improved:s = ""+file.getAbsolutePath()
just writes = file.getAbsolutePath()
. What's wrong with using aListView
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 useteste
as an event handler but it has the incorrect signature. It should have a single parameter whose type is the appropriate subclass ofjavafx.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
add a comment |
active
oldest
votes
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.
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.
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 aListView
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 ofjavafx.event.Event
or no parameter at all. See the Controller Method Event Handlers section of Introduction to FXML.– Slaw
2 days ago