728x90
main.java
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("testTableVIew.fxml"));
Scene scene = new Scene(root, 600, 400);
scene.getStylesheets().add(getClass().getResource("application.css")
.toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
testController .java
public class testController implements Initializable{
@FXML
private TableView<Person> tableView;
@FXML
private TableColumn<Person, String> nameCol;
@FXML
private TableColumn<Person, Integer> ageCol;
ObservableList<Person> data = FXCollections.observableArrayList();
public testController() {
data.add(new Person("이름1", 24));
data.add(new Person("이름",25));
}
@SuppressWarnings("unchecked")
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
nameCol.setCellValueFactory(cellData -> cellData.getValue().getName());
ageCol.setCellValueFactory(cellData -> cellData.getValue().getAge().asObject());
tableView.setItems(data);
}
public void cancel() {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirmation Dialog");
alert.setHeaderText("Look, a Confirmation Dialog");
alert.setContentText("Are you ok with this?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
// ... user chose OK
System.out.println("OK");
} else {
// ... user chose CANCEL or closed the dialog
System.out.println("취소");
}
}
}
public class Person {
private StringProperty name;
private IntegerProperty age;
public Person(String name, int age) {
super();
this.name = new SimpleStringProperty(name);
this.age = new SimpleIntegerProperty(age);
}
public StringProperty getName() {
return name;
}
public void setName(StringProperty name) {
this.name =name;
}
public IntegerProperty getAge() {
return age;
}
public void setAge(IntegerProperty age) {
this.age =age;
}
}
module Project_fx {
exports application;
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;
requires javafx.fxml;
requires javafx.media;
requires javafx.swing;
requires javafx.web;
requires javafx.swt;
opens application to javafx.fxml; //특히 이거 설정 안하면 에러남
}
리스트뷰
public void setItem() {
//임시로 값 넣기
AttractionReview AR1 = new AttractionReview("r1", "20200525","리뷰제목1","20140299","관광지명","좋다",5);
AttractionReview AR2 = new AttractionReview("r2", "20200525","리뷰제목2","20140299","관광지명","좋다",5);
AttractionReview AR3 = new AttractionReview("r3", "20200525","리뷰제목3","20140299","관광지명","좋다",5);
//
ObservableList<String> list = FXCollections.observableArrayList();
list.add(AR1.getReviewId() + "\n" + AR1.getUserId()+"\n"+AR1.getReviewTitle());
list.add(AR2.getReviewId());
list.add(AR3.getReviewId());
reviewListView.setItems(list);
}
//값 얻기
public String getListValue() {
return reviewListView.getSelectionModel().getSelectedItem();
}
getSelectedIndex() 할 경우
인덱스의 값이 나온다.
참고사이트
'Language > JAVA' 카테고리의 다른 글
인텔리제이 설치를 위한 교육용 라이센스 받기 (0) | 2020.08.22 |
---|---|
JDBC , DB , try-with-resources (Java 1.7이상) 자원해제 (0) | 2020.06.01 |
javafx 참고 라이브러리 (0) | 2020.05.03 |
코딩 실력 참고 사이트 / 공공데이터 (0) | 2020.03.18 |
UML 관련 사이트 / 객체지향SW (0) | 2020.03.06 |
댓글