我在TabPane中有3个标签,每个标签都有一个不同文本和不同长度的文本区域.我想根据每个标签中的长度自动调整文本区域.我不明白我该怎么办?使用场景构建器?css?javaFX方法?提前致谢 ...
rs = statement.executeQuery("select * from user");
while (rs.next()) {
String username = rs.getString("staffname");
options1.add(username); // ObservableList<String> options1 = FXCollections.observableArrayList();
}
cb.setItems(options1); // cb is ComboBox object
cb.setPromptText("Select Your Account");
cb.setPrefSize(280, 30);
Button bt = new Button("Sign In");
bt.setFont(Font.font("Calibri", FontWeight.NORMAL, 17));
bt.setStyle(" -fx-base: #333333;");
bt.setTextFill(Color.WHITE);
bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
setCenter(userSignin());
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(FrontPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我从数据库中读取一些值并在ComboBox中显示它的代码.现在,我需要在按下Button时删除ComboBox中的所有值.我想一键删除所有内容.我该怎么做 ?
我想为窗格的按钮设置相同的宽度,但在显示舞台之前没有按钮宽度.如何在不显示舞台的情况下获得宽度?
由于未定义宽度而无效的代码示例:
public static HBox createHorizontalButtonBox(final List<Button> buttons, final Pos alignment, final double spacing, final boolean sameWidth) {
HBox box = new HBox(spacing);
box.setAlignment(alignment);
box.getChildren().addAll(buttons);
if (sameWidth && buttons.size() > 1) {
double max = maxWidth(buttons);
for (Button b : buttons) {
b.setPrefWidth(max);
}
}
return box;
}
Run Code Online (Sandbox Code Playgroud) 我一遍又一遍地试过这个嵌套控制器的东西,它只是不起作用'我'.我不知道为什么我能得到一些像这样容易的东西.我按照这个例子
<VBox fx:controller="com.foo.MainController">
<fx:include fx:id="dialog" source="dialog.fxml"/>
...
</VBox>
public class MainController extends Controller {
@FXML private Window dialog;
@FXML private DialogController dialogController;
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码:app.Main.fxml
<AnchorPane prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="app.MainController">
<children>
<Button layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
<Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" />
<fx:include source="InnerFile.fxml" fx:id="innerfile"/>
</children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)
app.MainController.java
public class MainController {
@FXML
private Label label;
@FXML
private Button button;
@FXML
private InnerFileController controller;
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
} …Run Code Online (Sandbox Code Playgroud) 当我尝试运行我的应用程序时,我收到此错误:
Caused by: java.lang.NullPointerException
at WebOpenController.<init>(WebOpenController.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
... 22 more
Run Code Online (Sandbox Code Playgroud)
第19行是这个私有的WebEngine engine = view.getEngine();
这是班级:
public class WebOpenController implements Initializable {
@FXML
private WebView view;
private String link = "http://google.com";
private WebEngine engine = view.getEngine();
@Override
public void initialize(URL location, ResourceBundle resources) {
engine.load(link);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我做WebView view = new WebView时它会工作,但它不会在启动时打开页面
我确实在scenebuilder中设置了fx-id
我有一个简单的javafx样本tableView.我想在列标题标签下插入一个文本字段来过滤表数据.
我找到了一个例子,但它插入了文本字段而不是标题标签,而我想同时拥有标签和文本字段:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TableWithTextHeaders extends Application {
public static void main(String[] args) { launch(args); }
@Override
public void start(Stage stage) {
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setCellValueFactory(new PropertyValueFactory<Person,String>("firstName"));
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setCellValueFactory(new PropertyValueFactory<Person,String>("lastName"));
TableColumn searchCol = new TableColumn<>();
TableView table = new TableView();
table.getColumns().addAll(firstNameCol, lastNameCol);
table.setItems(FXCollections.observableArrayList(
new Person("Jacob", "Smith"),
new Person("Isabella", "Johnson"),
new …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序创建一个自定义TitleBar,我正在为我实现Minimize && Maximize && Close按钮Stage.我通过使用TRANSPARENT StageStyle
我最大化这种方式
Stage.setHeight(Screen.getPrimary().getVisualBounds().getHeight()-Margins);
Stage.setWidth(Screen.getPrimary().getVisualBounds().getWidth() -Margins);
Stage.setX(1.0);
Stage.setY(0.0);
// let others know about it
Run Code Online (Sandbox Code Playgroud)
我这样关闭
// stop all custom stuffs
Stage.close();
Run Code Online (Sandbox Code Playgroud)
&&我想最小化任何方式来实现?
最小化是我的问题..我已经尝试了,我试过hide(),toBack()- (如果你在屏幕上有成堆的窗户,这似乎说服你)他们都不工作
我正在尝试导入Alert类但不起作用.Java 1.8.0_31是否有javafx.scene.control.Alert类可以将它导入到我的项目中吗
我有一个JavaFX TableView,我正在使用ObservableList of Tasks填充.我一直在尝试创建一个显示每行索引的列,它作为表中任务的ID,但我在这里尝试了这个方法,其他来源的类似方法也没有成功.
我的代码供参考,没有表面错误(就Eclipse而言):
@FXML private TableColumn<Task, String> taskIndexCol;
Callback<TableColumn<Task, String>, TableCell<Task, String>> cb =
new Callback<TableColumn<Task, String>, TableCell<Task, String>>(){
@Override
public TableCell<Task, String> call(TableColumn<Task, String> col) {
TableCell<Task, String> cell = new TableCell<Task, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null) {
setText("");
} else {
setText(getIndex()+"");
}
}
};
return cell;
}
};
taskIndexCol.setCellFactory(cb);
Run Code Online (Sandbox Code Playgroud)
目前,当我尝试设置列的CellFactory时,我的代码给了我一个NullPointerException.我已经尝试了一个填充的任务列表,但这没有帮助.我已经被困了很长时间了 - 理论上这应该很简单,因为它只是对行进行编号?感觉就像是在跳过一百万个箍来做一些令人沮丧的简单事情.
编辑:最后一行给了我NPE.
我正在尝试使用此方法在JavaFx CSS中加载自定义字体
@font-face {
font-family: 'Roboto';
src: url('fonts/Roboto-Medium.ttf');
}
Run Code Online (Sandbox Code Playgroud)
我已经用正确的路径完成了所有正确的操作,但是出现了此错误
Nov 28, 2015 4:49:18 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
INFO: Could not load @font-face font [file:/C:/Users/RootUser/Desktop/Java8%20projects/RemoteViewer/out/production/JavaFxApplication/application/fonts/Roboto-Medium.ttf]
Run Code Online (Sandbox Code Playgroud)
这是我的项目结构“截图”
请注意,我正在使用intellij Idea作为我的IDE。