小编apr*_*l21的帖子

如何从TableView中删除选定的行?(带有 FXML 的 JavaFX)

所以,我试图在我的程序中删除 TableView 中突出显示的行。

我在网上看了很多教程,但真的无法理解这一点。我遵循了 Eclipse 中的 CodeMakery 的示例,但我无法让它在 IntelliJ 上工作(因为一些明显的 JDK 问题?)

这是来自 CodeMakery 的代码:

private void handleDeletePerson() {
    int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
    if (selectedIndex >= 0) {
        personTable.getItems().remove(selectedIndex);
    } else {
        // Nothing selected.
        Alert alert = new Alert(AlertType.WARNING);
        alert.initOwner(mainApp.getPrimaryStage());
        alert.setTitle("No Selection");
        alert.setHeaderText("No Person Selected");
        alert.setContentText("Please select a person in the table.");

        alert.showAndWait();
    }
}
Run Code Online (Sandbox Code Playgroud)

你能帮我理解如何使选定的行被删除吗?

javafx tableview fxml

5
推荐指数
1
解决办法
6210
查看次数

使用 javafx 和场景生成器创建音乐播放器

我正在尝试创建我自己的 iTunes 版本。我正在尝试创建一个音乐播放器,这是我的方法:

public void audioPlayerButtons(ActionEvent actionEvent) {
    if (actionEvent.getSource() == playbtn) {

        String bip = "/Users/april121/Work/MyMusic!/src/sample/Songs/01 Clarity.m4a";
        Media hit = new Media(bip);
        MediaPlayer mediaPlayer = new MediaPlayer(hit);
        MediaPlayer.play();

    }

   else (actionEvent.getSource()== pausebtn){
           MediaPlayer.pause();
   }

   else (actionEvent.getSource()==forwardbtn){
       MediaPlayer.seek(MediaPlayer.getStartTime());
       MediaPlayer.stop();
   }

   else (actionEvent.getSource()==backwardbtn){
//to be finished
    }
Run Code Online (Sandbox Code Playgroud)

但我现在已经尝试了几个小时 - 无论是通过从 Maven 导入库还是硬编码,它都不起作用。

我希望它显示正在播放的内容并具有基本功能,即。播放、暂停、快退和快进,并有进度条。

这是它显示的错误:

non-static method can't be accessed in static context. And the part that is causing the error is the ".stop()" or ".play()" bits
Run Code Online (Sandbox Code Playgroud)

但我不明白为什么 - 因为我的方法无论如何都是非静态的

java media media-player fxml

0
推荐指数
1
解决办法
2570
查看次数

标签 统计

fxml ×2

java ×1

javafx ×1

media ×1

media-player ×1

tableview ×1