Dies ist meine erste Post.JavaFX Textbereich: Hinzufügen von "-" am Ende jeder Zeile
Ich benutze NetBeans IDE und ich benutze Scene Builder für mein JavaFX Projekt. Ich habe einen Textbereich mit den Variablen „Definitionen“ Ich habe auch eine Schaltfläche mit der Aktion
void addAction(ActionEvent event) {
}
ich im Textbereich zu machen Linie versuchen am Ende mit „-“.
es sichtbar zu machen: input:
happy
sad
good
bad
output:
happy -
sad -
good -
bad -
Ich habe dies für Loop:
for (int i = 0 ; definitions.getText().split("\\n"); i++){
String previous = definitions.getText();
definitions.setText(previous + " - ");
}
aber die Ausgabe ist:
happy
sad
good
bad - - - -
Könnte mir jemand helfen? Vielen Dank an alle. MineRockers
Hier ist der vollständige Code für den Fall, Sie Jungs brauchen es:
package vocabulary.javafx;
import java.net.URL;
import java.awt.Desktop;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
public class FXMLDocumentController implements Initializable {
//Declaration...
private boolean Email;
private boolean Save;
private String Word;
@FXML
private Button add;
@FXML
private TextArea sentences;
@FXML
private Button searchS;
@FXML
private TextField helpD;
@FXML
private Button finish;
@FXML
private Label label;
@FXML
private TextField helpS;
@FXML
private TextArea definitions;
@FXML
private Button searchD;
@FXML
void addAction(ActionEvent event) {
String previous = definitions.getText();
String[] linecountS = definitions.getText().split("\n");
for()
int lineCount = Integer.parseInt(linecountS);
//for (int i = 0 ; definitions.getText().split("\\n"); i++){
// String previous = definitions.getText();
// definitions.setText(previous + "-");
//}
}
@FXML
void helpDAction(ActionEvent event) {
//Enter Key Pressed
Word = helpD.getText();
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI("http://www.dictionary.com/browse/" + Word + "?s=t"));
} catch (URISyntaxException | IOException ex) {
}
}
}
@FXML
void helpSAction(ActionEvent event) {
//Enter Key Pressed
Word = helpS.getText();
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI("http://sentence.yourdictionary.com/" + Word));
} catch (URISyntaxException | IOException ex) {
}
}
}
@FXML
void searchDAction(ActionEvent event) {
//Button Clicked
Word = helpD.getText();
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI("http://www.dictionary.com/browse/" + Word + "?s=t"));
} catch (URISyntaxException | IOException ex) {
}
}
}
@FXML
void searchSAction(ActionEvent event) {
//Button Clicked
Word = helpS.getText();
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI("http://sentence.yourdictionary.com/" + Word));
} catch (URISyntaxException | IOException ex) {
}
}
}
@FXML
void finishAction(ActionEvent event) {
String Content1 = definitions.getText();
String Content2 = sentences.getText();
String Finalized = "Auto-generated message by Vocabulary 2.0 by MineRocker\n\nDefinitions:\n" + Content1 + " \n\n\nSentences:\n" + Content2;
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI("gmail.com"));
} catch (URISyntaxException | IOException ex) {
}
FileWriter fileWriter;
try {
fileWriter = new FileWriter("AFile.txt");
try (BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {
bufferedWriter.write(Finalized);
}
} catch (IOException ex) {
}
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
Jungs, jeder Vorschlag ist gut, don‘ Ich zögere, zu kommentieren oder eine Antwort zu geben! –