我正在尝试制作具有最小宽度和高度的标签,用于触摸屏上的手指大小,而不是内部文本的大小.
.tab-pane *.tab-header-area *.tab-header-background {
-fx-background-color:transparent;
-fx-tab-min-width:120px;
-fx-tab-max-width:120px;
-fx-tab-min-height:50px;
-fx-tab-max-height:50px;
}
.tab {
-fx-font-family: Arial;
-fx-font-size: 18;
-fx-background-color:royalblue ;
}
.tab:selected {
-fx-background-color:blue ;
}
Run Code Online (Sandbox Code Playgroud)
颜色和字体都有效,但尺寸无效.我尝试了许多尺寸,使用px和em,但没有效果.
TabPane tabPane = new TabPane();
Tab tab1 = new Tab();
tab1.setText("Machine");
tab1.setClosable(false);
Tab tab2 = new Tab();
tab2.setText("Shifts");
tab2.setClosable(false);
tabPane.getTabs().addAll(tab1, tab2);
Run Code Online (Sandbox Code Playgroud) 在这个例子中,我希望我的一个列TableView从LocalDateTime(在源数据模型中)格式化为格式为"yyyy/MM/dd kk:mm" TableColumn.(注意:对于渲染,而不是编辑)好吧,在表视图中显示时,我需要在一些数据模型中使用Local/ZonedDateTime类型.做这个的最好方式是什么?(我没有注意到Oracle Table View教程中此类功能的示例).
编辑添加:或者,可能将数据模型中的值保持为String(格式化),并LocalDateTime在处理记录时使用转换为最佳?
import java.time.LocalDateTime;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
final ObservableList<Foo> data = FXCollections.observableArrayList();
LocalDateTime ldt = LocalDateTime.now();
data.add(new Foo(ldt));
data.add(new Foo(ldt.plusDays(1)));
data.add(new Foo(ldt.plusDays(2)));
TableView<Foo> table = new TableView<Foo>();
table.setItems(data);
TableColumn<Foo, LocalDateTime> ldtCol = new TableColumn<Foo, LocalDateTime>("LDT");
// --- Set cell factory …Run Code Online (Sandbox Code Playgroud) 我知道有类似的问题,并且在不同的日期,但我会在这里放一个SSCCE,并试着简单地问这个问题.
我希望能够更新数据模型,并在其上自动更新任何视图,这样任何更新模型的调用者都不会知道目前的任何视图.这是我到目前为止学习/尝试过的,没有调用TableView.refresh()它也没有更新.我错过了什么?
main.java:
package application;
import javafx.application.Application;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
public class Main extends Application {
@Override
public void start(Stage stage) {
// data
ObservableList<Crew> data = FXCollections.observableArrayList();
data.addAll(new Crew(1, "A"), new Crew(2, "B"));
// table
TableColumn<Crew, Integer> crewIdCol = new TableColumn<Crew, Integer>("Crew ID");
crewIdCol.setCellValueFactory(new PropertyValueFactory<Crew, Integer>("crewId"));
crewIdCol.setMinWidth(120);
TableColumn<Crew, String> crewNameCol = new TableColumn<Crew, String>("Crew Name");
crewNameCol.setCellValueFactory(new PropertyValueFactory<Crew, String>("crewName")); …Run Code Online (Sandbox Code Playgroud) 我写了以下内容,在右侧生成一个工具栏,只有它中的两个按钮一样高.我希望工具栏能够运行窗口的高度 - 从上到下.我需要做什么?
import javax.swing.*;
import java.awt.*;
public class AmtFrame extends JFrame {
private JToolBar toolBar = null;
private JButton[] buttons = new JButton[5];
private Container cp = null;
AmtFrame() {
super("AMT");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1000, 600);
// tool bar
toolBar = new JToolBar("TaskBar", JToolBar.VERTICAL);
toolBar.add(buttons[0] = new JButton("Data Entry"));
toolBar.add(buttons[1] = new JButton("Operations"));
// layout
cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(toolBar, BorderLayout.EAST);
}
public static void main(String[] args) {
new AmtFrame().setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个TextFieldCSS填充颜色,和Label.但是当我尝试Text控件时,我还没弄清楚如何在CSS中设置填充颜色(我尝试过很多东西).
Label label = new Label("Machine ID");
TextField textField = new TextField("1");
Text text = new Text("1");
Run Code Online (Sandbox Code Playgroud)
的CSS:
.text-input {
-fx-text-fill: blue;
}
.label {
-fx-text-fill: blue;
}
Run Code Online (Sandbox Code Playgroud)