我已经创建了一个Java/JavaFX控制台,现在我面临一个例外:Console reports an Internal error.The error is: java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-5.控制台的代码:
package core.console;
import javafx.concurrent.Service;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
import java.io.*;
import java.util.ResourceBundle;
public class Console implements Runnable{
private Console(ResourceBundle resourceBundle) throws IOException {
FXMLLoader loader = new FXMLLoader(this.getClass().getResource("Console.fxml"), resourceBundle);
Parent root = (Parent) loader.load();
controller = loader.getController();
Scene scene = new Scene(root);
stage = new Stage();
stage.setScene(scene);
textArea = controller.getTextArea();
show();
PipedOutputStream pout=new PipedOutputStream(this.pin);
System.setOut(new PrintStream(pout,true)); …Run Code Online (Sandbox Code Playgroud) 我正在尝试MenuButton使用JavaFX而不是通过代码修改箭头的颜色CSS。
我在里面找到它caspian.css:
.menu-button > .arrow-button > .arrow {
-fx-background-insets: 1 0 -1 0, 0;
-fx-background-color: -fx-mark-highlight-color, -fx-mark-color;
-fx-padding: 0.25em; /* 3 */
-fx-shape: "M 0 -3.5 v 7 l 4 -3.5 z";
}
Run Code Online (Sandbox Code Playgroud)
我试图使用类似的东西:
menubutton.lookup(".arrow");
Run Code Online (Sandbox Code Playgroud)
但它抛出 NullPointerException
当我这样做时:
System.out.println(this.getStyleClass().toString());
它仅表明:menu-button仅。
所以任何人都可以给我一种无需使用CSS即可使用Java对其进行修改的方法吗?
我有一个表视图和表列,我替换了排序.
排序事件:
nameColumn.sortTypeProperty().addListener(
new ChangeListener<SortType>() {
@Override
public void changed(
ObservableValue<? extends SortType> observable,
SortType oldValue, SortType newValue) {
FXListSorter.sortPersonByName(fetchResults, newValue);
showFetchResultsByPage();
}
});
Run Code Online (Sandbox Code Playgroud)
清单分拣机:
public static void sortPersonByName(ObservableList<PersonBean> list,
SortType sortType) {
FXCollections.sort(list, new Comparator<PersonBean>() {
@Override
public int compare(PersonBean p1, PersonBean p2) {
if (sortType.equals(SortType.ASCENDING)) {
return p1.toString().compareToIgnoreCase(p2.toString());
} else {
return p2.toString().compareToIgnoreCase(p1.toString());
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
显示获取的结果:
private void showFetchResultsByPage() {
int start = currentPageIndex * pageSize;
if (start > fetchResults.size()) {
return;
}
int maxValForPage = …Run Code Online (Sandbox Code Playgroud) 使用此代码我初始化组合框
@FXML
private ComboBox category;
Run Code Online (Sandbox Code Playgroud)
并使用以下方法获取价
String Category = category.getValue().toString();
Run Code Online (Sandbox Code Playgroud)
并将值插入mysql数据库.现在,在类别组合框中插入下一个值之前,我需要将数据库中的值导入到组合框中的下拉列表中,并且值应该显示在组合框中.
我正试图设置Image一个ImageView对象.我的代码:
Image photo = new Image("http://example.com/image.jpg", 100, 0, false, false);
ImageView face = new ImageView();
face.setImage(photo);
Run Code Online (Sandbox Code Playgroud)
我在第2行和第3行遇到错误,但我非常关注文档.摘自文档:
// load the image
Image image = new Image("flower.png");
// simple displays ImageView the image as is
ImageView iv1 = new ImageView();
iv1.setImage(image);
Run Code Online (Sandbox Code Playgroud)
错误
第2行:
java: constructor ImageView in class javax.swing.text.html.ImageView cannot be applied to given types;
required: javax.swing.text.Element
found: no arguments
reason: actual and formal argument lists differ in length
Run Code Online (Sandbox Code Playgroud)
第3行:
java: cannot find symbol
symbol: …Run Code Online (Sandbox Code Playgroud) 如何检测何时CheckBoxTreeItem选择或未选择?
我是否使用事件处理程序或更改侦听器?我要检查什么事?是否有我可以收听的事件列表,如checkboxtreeitem.selection或其他什么?
谢谢
是否可以在FXML中调整TableView的大小,其中每列的相对大小调整?我知道在代码中这是可能的,但我特意寻找FXML方法.
这是目前的做法:
<BorderPane xmlns:fx="http://javafx.com/fxml">
<fx:define>
<Double fx:id="tableViewWidth" fx:value="600"/>
</fx:define>
<center>
<TableView fx:id="expensesTableView" editable="true" prefWidth="${tableViewWidth}">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn text="Title" prefWidth="${tableViewWidth * 3}">
<cellValueFactory>
<PropertyValueFactory property="title" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Category" prefWidth="${tableViewWidth * 3}">
<cellValueFactory>
<PropertyValueFactory property="category" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Period" prefWidth="${tableViewWidth * 2}">
<cellValueFactory>
<PropertyValueFactory property="period" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Value" prefWidth="${tableViewWidth * 2}">
<cellValueFactory>
<PropertyValueFactory property="value" />
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
</center>
</BorderPane>
Run Code Online (Sandbox Code Playgroud)
乘法部分似乎不起作用.
我正在尝试显示我创建的上下文菜单,当我右键单击窗格或图像视图时((在请求的上下文菜单上)).问题是它们似乎没有setContextMenue方法,不像标签和按钮......等.如何将上下文菜单关联到似乎不接受上下文菜单的节点?
@FXML
Button button1, button2;
@FXML
Pane mainPane;
@FXML
ImageView image;
private void initContextMenu() {
final ContextMenu contextMenu = new ContextMenu();
final MenuItem item1 = new MenuItem("open a file");
final MenuItem item2 = new MenuItem("quit");
contextMenu.getItems().addAll(item1, item2);
// not possible
image.setContextMenu(contextMenu);
// possible
button1.setContextMenu(contextMenu)
Run Code Online (Sandbox Code Playgroud) 我在JavaFX标签中遇到了一组非常奇怪的情况,包括文本换行和居中对齐.我确定我做错了什么或者说不明智,但我似乎无法弄清楚我做错了什么.
基本上,我正在尝试将标题放在图块窗格上,并将该标题置于中心位置.此外,当窗口调整大小时,我想要包装标题.当标题没有被包裹时(例如:一行),它就不再是中心了.一旦它包裹起来,它就会再次集中.以下是一些产生效果的示例代码:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.apache.commons.lang.RandomStringUtils;
public class Foo extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
TilePane panel = new TilePane();
panel.setTileAlignment(Pos.CENTER_LEFT);
for (int i = 0; i < 25; i++)
{
panel.getChildren().add(new Label(RandomStringUtils.randomAlphabetic(10)));
}
Label title = new Label("Lorem ipsum dolor sit amet, consectetur adipiscing elit");
title.setStyle("-fx-font-size: 16; -fx-font-weight: bold; -fx-wrap-text:true; -fx-text-alignment: center -fx-border-color:black;");
title.minWidthProperty().bind(Bindings.add(-30, primaryStage.widthProperty()));
title.setTextAlignment(TextAlignment.CENTER);
VBox box = new …Run Code Online (Sandbox Code Playgroud) 我已经开发了一些代码,我有一个Set的UserS:
public class ParkCentral{
private Set<User> users = new HashSet<>();
}
Run Code Online (Sandbox Code Playgroud)
然后,在另一个类中,我正在开发GUI和的TableView User。问题是我无法从中创建ObervableList一个Set。我希望所做的更改ParkCentral.users将反映在TableView上。
是否可以在不更改ParkCentral实现的情况下而不更改Setto List?
为什么TableView仅适用于ObservableList而不适用于ObservableSet或ObservableMap?