- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 filechooser 获取的文件名填充表,在 fileName 列中,如何在 Tableview 的此列中包含文件名?
这是与 sceneBuilder 的界面
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import javafx.scene.media.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<VBox fx:id="VBox" prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
<children>
<MenuBar fx:id="MenuBar" nodeOrientation="RIGHT_TO_LEFT" VBox.vgrow="NEVER">
<menus>
<Menu fx:id="Help" mnemonicParsing="false" text="Help">
<items>
<MenuItem fx:id="GuidaOnline" mnemonicParsing="false" text="GuidaOnline" />
<MenuItem fx:id="Manuale" mnemonicParsing="false" text="Manuale" />
<SeparatorMenuItem fx:id="Separator" mnemonicParsing="false" />
<MenuItem fx:id="About" mnemonicParsing="false" text="About" />
<MenuItem fx:id="Riconoscimenti" mnemonicParsing="false" text="Riconoscimenti" />
</items>
</Menu>
</menus>
</MenuBar>
<SplitPane fx:id="Split1" dividerPositions="0.289532293986637, 0.7806236080178174" focusTraversable="true" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<items>
<AnchorPane fx:id="Anchor1">
<children>
<TabPane fx:id="Tab1" layoutX="6.0" layoutY="5.0" prefHeight="391.0" prefWidth="245.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="TabElenco" text="Elenco suoni">
<content>
<ScrollPane fx:id="Scroll1" prefHeight="362.0" prefWidth="227.0">
<content>
<TableView fx:id="Table1">
<columns>
<TableColumn fx:id="colCount" prefWidth="26.0" text="#" />
<TableColumn fx:id="colName" prefWidth="124.0" text="NomeFile" />
<TableColumn fx:id="colDate" prefWidth="79.0" text="Data" />
</columns>
</TableView>
</content>
</ScrollPane>
</content>
</Tab>
<Tab fx:id="tabRegistra" text="Registra" />
</tabs>
</TabPane>
<Button fx:id="btnAggiungi" layoutX="18.0" layoutY="437.0" mnemonicParsing="false" onAction="#AddFileAudio" prefHeight="43.0" prefWidth="98.0" text="Aggiungi" />
<Button fx:id="btnRimuovi" layoutX="145.0" layoutY="437.0" mnemonicParsing="false" prefHeight="43.0" prefWidth="98.0" text="Rimuovi" />
</children>
</AnchorPane>
<ScrollPane fx:id="Scroll2" prefHeight="551.0" prefWidth="496.0" />
<AnchorPane fx:id="Anchor2" prefHeight="551.0" prefWidth="205.0">
<children>
<Label fx:id="lblAnalisiSing" alignment="CENTER" layoutX="14.0" layoutY="14.0" opacity="0.5" prefHeight="37.0" prefWidth="142.0" text="Analisi singola:" />
<Button fx:id="btnSpettrogram" layoutX="14.0" layoutY="51.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="142.0" text="Spettrogramma" />
<Button fx:id="btnSpettro" layoutX="15.0" layoutY="83.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="142.0" text="Spettro" />
<Button fx:id="btnFormanti" layoutX="14.0" layoutY="117.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="142.0" text="Formanti" />
<Button fx:id="btnPicchi" layoutX="15.0" layoutY="150.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="142.0" text="Picchi" />
<Button fx:id="btnIntensita" layoutX="14.0" layoutY="183.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="142.0" text="Intensità" />
<Button fx:id="btnPulsazioni" layoutX="15.0" layoutY="217.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="142.0" text="Pulsazioni" />
<Button fx:id="btnAnalizza" layoutX="14.0" layoutY="395.0" mnemonicParsing="false" prefHeight="43.0" prefWidth="142.0" text="Analizza" />
<Label fx:id="lblAnalisiCom" alignment="CENTER" layoutX="16.0" layoutY="352.0" opacity="0.5" prefHeight="27.0" prefWidth="142.0" text="Analisi completa:" />
</children>
</AnchorPane>
</items>
</SplitPane>
<HBox id="HBox" fx:id="Hbox" alignment="CENTER_LEFT" spacing="5.0" VBox.vgrow="NEVER">
<children>
<Label fx:id="LeftStatus" maxHeight="1.7976931348623157E308" maxWidth="-1.0" HBox.hgrow="ALWAYS">
<font>
<Font size="11.0" fx:id="x3" />
</font>
<textFill>
<Color blue="0.625" green="0.625" red="0.625" fx:id="x4" />
</textFill>
</Label>
<Pane fx:id="Pane" prefHeight="-1.0" prefWidth="-1.0" HBox.hgrow="ALWAYS" />
<Label fx:id="RightStatus" font="$x3" maxWidth="-1.0" textFill="$x4" HBox.hgrow="NEVER" />
</children>
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
</HBox>
</children>
</VBox>
这是主类
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("StartGUI.fxml"));
Scene scene = new Scene(root,900,550);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
这是一个 Controller
/**
* Sample Skeleton for 'StartGUI.fxml' Controller Class
*/
package application;
import java.io.File;
import java.io.PipedInputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.util.Callback;
import utility.TableFileValue;
import utility.Person;
import utility.PopulateTable;
import javafx.beans.property.ReadOnlyIntegerWrapper;
import javafx.beans.property.ReadOnlyStringWrapper;
public class Controller implements Initializable{
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // fx:id="Help"
private Menu Help; // Value injected by FXMLLoader
@FXML // fx:id="btnSpettro"
private Button btnSpettro; // Value injected by FXMLLoader
@FXML // fx:id="lblAnalisiCom"
private Label lblAnalisiCom; // Value injected by FXMLLoader
@FXML // fx:id="tabRegistra"
private Tab tabRegistra; // Value injected by FXMLLoader
@FXML // fx:id="Split1"
private SplitPane Split1; // Value injected by FXMLLoader
@FXML // fx:id="MenuBar"
private MenuBar MenuBar; // Value injected by FXMLLoader
@FXML // fx:id="lblAnalisiSing"
private Label lblAnalisiSing; // Value injected by FXMLLoader
@FXML // fx:id="btnSpettrogram"
private Button btnSpettrogram; // Value injected by FXMLLoader
@FXML // fx:id="btnAnalizza"
private Button btnAnalizza; // Value injected by FXMLLoader
@FXML // fx:id="ColData"
private TableColumn<PopulateTable, String> colDate; // Value injected by FXMLLoader
@FXML // fx:id="GuidaOnline"
private MenuItem GuidaOnline; // Value injected by FXMLLoader
@FXML // fx:id="ColNome"
private TableColumn<PopulateTable, String> colName; // Value injected by FXMLLoader
@FXML // fx:id="Table1"
private TableView<PopulateTable> Table1; // Value injected by FXMLLoader
@FXML // fx:id="Hbox"
private HBox Hbox; // Value injected by FXMLLoader
@FXML // fx:id="btnPulsazioni"
private Button btnPulsazioni; // Value injected by FXMLLoader
@FXML // fx:id="btnRimuovi"
private Button btnRimuovi; // Value injected by FXMLLoader
@FXML // fx:id="ColNum"
private TableColumn<PopulateTable,Integer> colCount; // Value injected by FXMLLoader
@FXML // fx:id="tabElenco"
private Tab tabElenco; // Value injected by FXMLLoader
@FXML // fx:id="RightStatus"
private Label RightStatus; // Value injected by FXMLLoader
@FXML // fx:id="Scroll2"
private ScrollPane Scroll2; // Value injected by FXMLLoader
@FXML // fx:id="Scroll1"
private ScrollPane Scroll1; // Value injected by FXMLLoader
@FXML // fx:id="Pane"
private Pane Pane; // Value injected by FXMLLoader
@FXML // fx:id="About"
private MenuItem About; // Value injected by FXMLLoader
@FXML // fx:id="Anchor1"
private AnchorPane Anchor1; // Value injected by FXMLLoader
@FXML // fx:id="Anchor2"
private AnchorPane Anchor2; // Value injected by FXMLLoader
@FXML // fx:id="LeftStatus"
private Label LeftStatus; // Value injected by FXMLLoader
@FXML // fx:id="btnAggiungi"
private Button btnAggiungi; // Value injected by FXMLLoader
@FXML // fx:id="btnPicchi"
private Button btnPicchi; // Value injected by FXMLLoader
@FXML // fx:id="Manuale"
private MenuItem Manuale; // Value injected by FXMLLoader
@FXML // fx:id="btnFormanti"
private Button btnFormanti; // Value injected by FXMLLoader
@FXML // fx:id="btnIntensita"
private Button btnIntensita; // Value injected by FXMLLoader
@FXML // fx:id="Tab1"
private TabPane Tab1; // Value injected by FXMLLoader
@FXML // fx:id="x3"
private Font x3; // Value injected by FXMLLoader
@FXML // fx:id="x4"
private Color x4; // Value injected by FXMLLoader
@FXML // fx:id="VBox"
private VBox VBox; // Value injected by FXMLLoader
@FXML // fx:id="Riconoscimenti"
private MenuItem Riconoscimenti; // Value injected by FXMLLoader
@FXML // fx:id="Separator"
private SeparatorMenuItem Separator; // Value injected by FXMLLoader
String fileName;
@FXML
/**
* Apertura della finestra fileChooser per il caricamento dei file audio,
* sono accettati solo file con estensione .wav e .mp3.
* Estrazione del nome del file.
*
* @param event
*/
public void AddFileAudio(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Seleziona il file da caricare");
fileChooser.getExtensionFilters().addAll(
new ExtensionFilter("Audio Files", "*.wav", "*.mp3"));
File selectedFile = fileChooser.showOpenDialog(new Stage());
if (selectedFile != null) {
fileName = selectedFile.getName();
colName.setText(fileName);
}
}
public ObservableList<PopulateTable> list = FXCollections.observableArrayList(
new PopulateTable(1, fileName, "date1"),
new PopulateTable(2, "name2", "date2"),
new PopulateTable(3, "name3", "date3"));
public void initialize(URL location, ResourceBundle resource) {
colCount.setCellValueFactory(new PropertyValueFactory<PopulateTable,Integer>("count"));
colName.setCellValueFactory(new PropertyValueFactory<PopulateTable,String>("name"));
colDate.setCellValueFactory(new PropertyValueFactory<PopulateTable,String>("date"));
Table1.setItems(list);
assert Help != null : "fx:id=\"Help\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnSpettro != null : "fx:id=\"btnSpettro\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert lblAnalisiCom != null : "fx:id=\"lblAnalisiCom\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert tabRegistra != null : "fx:id=\"tabRegistra\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Split1 != null : "fx:id=\"Split1\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert MenuBar != null : "fx:id=\"MenuBar\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert lblAnalisiSing != null : "fx:id=\"lblAnalisiSing\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnSpettrogram != null : "fx:id=\"btnSpettrogram\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnAnalizza != null : "fx:id=\"btnAnalizza\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert colDate != null : "fx:id=\"ColData\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert GuidaOnline != null : "fx:id=\"GuidaOnline\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert colName != null : "fx:id=\"ColNome\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Table1 != null : "fx:id=\"Table1\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Hbox != null : "fx:id=\"Hbox\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnPulsazioni != null : "fx:id=\"btnPulsazioni\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnRimuovi != null : "fx:id=\"btnRimuovi\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert colCount != null : "fx:id=\"ColNum\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert tabElenco != null : "fx:id=\"tabElenco\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert RightStatus != null : "fx:id=\"RightStatus\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Scroll2 != null : "fx:id=\"Scroll2\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Scroll1 != null : "fx:id=\"Scroll1\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Pane != null : "fx:id=\"Pane\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert About != null : "fx:id=\"About\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Anchor1 != null : "fx:id=\"Anchor1\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Anchor2 != null : "fx:id=\"Anchor2\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert LeftStatus != null : "fx:id=\"LeftStatus\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnAggiungi != null : "fx:id=\"btnAggiungi\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnPicchi != null : "fx:id=\"btnPicchi\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Manuale != null : "fx:id=\"Manuale\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnFormanti != null : "fx:id=\"btnFormanti\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert btnIntensita != null : "fx:id=\"btnIntensita\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Tab1 != null : "fx:id=\"Tab1\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert x3 != null : "fx:id=\"x3\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert x4 != null : "fx:id=\"x4\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert VBox != null : "fx:id=\"VBox\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Riconoscimenti != null : "fx:id=\"Riconoscimenti\" was not injected: check your FXML file 'StartGUI.fxml'.";
assert Separator != null : "fx:id=\"Separator\" was not injected: check your FXML file 'StartGUI.fxml'.";
}
}
这是一个实用程序类 PopulateTable
package utility;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class PopulateTable {
private final SimpleIntegerProperty count;
private final SimpleStringProperty name;
private final SimpleStringProperty date;
public PopulateTable(int count, String name, String date) {
super();
this.count = new SimpleIntegerProperty(count);
this.name = new SimpleStringProperty(name);
this.date = new SimpleStringProperty(date);
}
public int getCount() {
return count.get();
}
public String getName() {
return name.get();
}
public String getDate() {
return date.get();
}
}
最佳答案
就这么做
Table1.getItems().add(new PopulateTable(0, fileName, ""));
即
public void AddFileAudio(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Seleziona il file da caricare");
fileChooser.getExtensionFilters().addAll(
new ExtensionFilter("Audio Files", "*.wav", "*.mp3"));
File selectedFile = fileChooser.showOpenDialog(new Stage());
if (selectedFile != null) {
String fileName = selectedFile.getName();
Table1.getItems().add(new PopulateTable(0, fileName, ""));
}
}
(您可能需要将第一个和第三个参数值更改为适当的值。)
关于java - 如何将javaFX中使用filechooser加载的文件名插入到表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533457/
我不知道这是不是问这种问题的最佳地点, 我看到一些 JavaFX伙计们,重新标记 一些问题通过替换 javafx来自 javafx-2并采用新的 javafx-8 .它被弃用了还是什么? 编辑 : 不
错误本身: Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.bas
这个想法是让一个应用程序在每个显示器上显示两个不同的窗口(阶段),该应用程序应该知道计算机有多少个显示器及其分辨率。 javafx有可能吗? 最佳答案 对于当前版本的 JavaFX (2.2),您可以
我正在将我的项目从 javafx 1.3 转换为 javafx 2.1。但我对 javafx.lang 有疑问包裹。 最佳答案 JavaFX 1.3 lang 包内容被拆分并移至下一个位置: 时长变为
当我尝试将标签添加到 gridpane 中时,如第二张图片所示,它不起作用。我已经尝试了很多东西,比如添加 CSS,但它仍然无法正常工作。为什么第 113 和 114 行不起作用? (opcje.se
我有一个JavaFX ContextMenu分配给滚动面板的鼠标右键单击。它会打开,但在滚动 Pane 外部单击时不会关闭。我可以在滚动 Pane 中添加另一个鼠标事件以将其隐藏,但这只能解决1个问题
我有一个tableview,其中附有一个可观察到的自定义类对象的列表(类类型:SalesInvoiceNetSale)。该表中的所有数据都可以正常显示。可观察列表中的最后一项是总计行(类类型:Sale
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我想知道如何在JavaFX中绘制半圆。我尝试使用Shape和QuadCurve,但无法制作出完美的半圆。 这是我要绘制的图片: 最佳答案 您链接的图片实际上是一个半圆环。您可以通过绘制嵌套的2条圆弧和
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我正在寻找 JavaFX 支持的图像类型(最新)列表,例如PNG、JPEG、TIFF。不同的搜索引擎没有帮助......知道从哪里开始吗? 更特别的是,我对 16 位灰度图像(不同格式)和罕见的受支持
我希望在 javafx 中让标签每 0.1 秒闪烁一次。文本显示在后台运行的 ImageView gif 的顶部。我将如何去做,或者您对最佳方法有什么建议? 谢谢 最佳答案 @fabian 的解决方案
我需要测试所选项目的值以调用不同的方法,因此我编写了添加侦听器的代码,但是该代码生成语法错误 @FXML private JFXComboBox cmbComp; cmbComp.valuePrope
我正在 Javafx 中编写一个非常简单的应用程序,其中舞台上有一个带有文本框的按钮作为一个场景。现在,我想要的行为是,当我单击按钮时,我可以使用另一个按钮加载另一个场景和舞台上的一个文本框,然后删除
编辑:如果用户单击“删除”以删除 ListView 中的项目,我会弹出一个警告框。它有效,但我希望它能超越原来的舞台。它出现在我的第一台显示器上。有什么方法可以设置警报显示时的位置吗? 请注意,“所有
我想使用 JavaFX 编写一个笔画绘图应用程序。我有一个压敏绘图板,如果能够读取笔的压力和倾斜值,那就太好了。 JavaFX 有一个 API 可以处理鼠标、触摸和滑动输入,但似乎没有任何东西可以产生
我在 JavaFX 中使用条形图和折线图。当我使两个图表大小相同并将它们放在同一位置时,它们完美地相互重叠。我如何使折线图显示在条形图的顶部。 目前我已将它们的不透明度设置为 0.7,这样它们“看起来
此问题与 this 相关。现在我想为字段值等于某个值的行着色。 @FXML private TableView tv_mm_view; @FXML private Ta
我有一个程序,可以生成高度图(0-255 的整数的 2D 数组),并使用 Shape3D“Box”对象为每个“像素”构建 3D View ,其高度与其在高度图中的值成比例。这会创建一个看起来很酷的四四
我想为 JavaFX 创建上下文菜单。这是我测试过的代码。但是由于某种原因,当我右键单击树节点时没有上下文菜单。你能帮我找出我的错误吗。 import java.util.Arrays; import
我是一名优秀的程序员,十分优秀!