我想知道是否可以在每个ListView项后添加一个图像按钮.例如:
那些红色方块应该有一个按钮.如果可能,我该如何处理项目按钮的点击事件?
编辑:如果有另一个控件可以做到,请告诉我.我正在测试TableView.
提前致谢!
我有一个ListView,想要以下内容:
那是我的代码.它的工作正常,除了偶数行:在鼠标悬停时,它以白色突出显示.所以,文字的白色并不能显示.它出什么问题了?
.list-cell:filled:selected:focused, .list-cell:filled:selected {
-fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
-fx-text-fill: white;
}
.list-cell:odd {
-fx-cell-hover-color: #0093ff;
-fx-background-color: white;
}
.list-cell:filled:hover {
-fx-cell-hover-color: #0093ff;
-fx-text-fill: white;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我有一个具有TreeView控件的FXML文件:
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml" fx:controller="test.MyControllerClass">
<TreeView fx:id="locationTreeView" layoutX="12.0" layoutY="158.0" prefHeight="193.0" prefWidth="471.0" />
Run Code Online (Sandbox Code Playgroud)
然后我的Java类控制器需要用这个TreeView包装并动态添加TreeItem.这就是问题,它没有加载那些TreeItem.这是我的控制器下面的测试代码:
public class MyControllerClass extends Application {
@FXML
private TreeView<String> locationTreeView;
@Override
public void start(Stage stage) throws Exception {
stage.initStyle(StageStyle.TRANSPARENT);
stage.getIcons().add(new Image(getClass().getResourceAsStream("myIcon.png")));
Parent root = FXMLLoader.load(getClass().getResource("myInterface.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
loadTreeItems();
stage.show();
}
// Just a simple example that still doesn't works
private void loadTreeItems() {
try {
TreeItem<String> root = new TreeItem<String>("Root Node");
root.setExpanded(true);
root.getChildren().addAll(
new TreeItem<String>("Item 1"),
new …Run Code Online (Sandbox Code Playgroud) 我想进行复杂的查询并将结果映射到 DTO。DTO 如下:
@Value(staticConstructor = "of")
public class TotalsDto {
LocalDate date;
long totals;
long totalPerCategory;
int categoryId;
String categoryName;
}
Run Code Online (Sandbox Code Playgroud)
我的存储库界面是从JpaRepository. 这是抛出一个IllegalArgumentException: Not a managed type,因为TotalsDto它本身不是实体。
存储库是:
@Repository
public interface TotalsRepository extends JpaRepository<TotalsDto, Integer> {
@Query(value = "SELECT ...", nativeQuery = true)
List<TotalsDto> getTotals(params...);
}
Run Code Online (Sandbox Code Playgroud)
查询正在从其他实体获取数据以构建 DTO。有什么方法可以将每一列映射到 DTO?我试图用下面的查询映射它,但它仍然得到Not a managed class.
SELECT my.package.TotalsDto.of(column1, subqueryResult1, subqueryResult2...)
Run Code Online (Sandbox Code Playgroud) 我需要在我的Java应用程序中创建持久存储,以便所有用户都可以访问它.所以我在Windows上研究java.util.prefs.Preferences和使用systemRoot()对我来说很好的工作,在Register上保存数据.但我真的在Linux(Ubuntu)上面临一些问题.我想使用其他应用程序已经使用的目录:/ usr/share /.所以,我正在尝试systemRoot在运行时将默认目录重定向到/ usr/share.这是我的代码:
System.setProperty("java -Djava.util.prefs.systemRoot", "/usr/share/myfolder");
Preferences pref = Preferences.systemRoot().node("/usr/share/myfolder");
Run Code Online (Sandbox Code Playgroud)
根据这个站点,我必须.systemPrefs在执行此命令行之前创建文件夹,并且它将隐式systemRoot()使用它.
当我执行我的程序时,我得到以下警告:
java.util.prefs.FileSystemPreferences syncWorld
WARNING Couldn't flush system prefs: java.util.prefs.BackingStoreException: /etc/.java/.systemPrefs/usr create failed.
所以我假设这System.setProperty不起作用.有什么建议吗?提前致谢!
我有一个扩展Application的类并调用主要阶段.这个主要阶段有一个Next Button,它将调用另一个阶段(选项阶段).选项阶段有一个上一个按钮.我想获得主要阶段的实例,处于用户单击"下一步"按钮之前的状态,例如:带有输入数据的文本字段或带有所选项目的组合框.我怎样才能做到这一点?
主要课程:
public class MainClass extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
final FXMLLoader loader = new FXMLLoader(getClass().getResource("interfaceOne.fxml"));
final Parent root = (Parent)loader.load();
final MyController controller = loader.<MyController>getController();
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
Platform.setImplicitExit(false);
controller.setStage(primaryStage);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
Run Code Online (Sandbox Code Playgroud)
}
myController的:
public class MyController{
// Some declarations ...
Stage stage = null;
public void setStage(Stage stage) {
this.stage = stage;
}
// Next button's action …Run Code Online (Sandbox Code Playgroud)