我想做什么?
我遇到了基于fxml的javafx应用程序的问题。我想创建一个简单的表单,输入一些应该存储在文件确认中的数值。
有什么问题?
表单完美地完成了它应该做的事情,除了我不能鼠标点击两个GridPanes中的元素。我可以通过按Tab键切换TextFields来输入值,但这当然不是理想的方法。我已经在AnchorPane中直接添加了TextFields和CheckBoxes,它们是可点击的,但在GridPanes中这不起作用。同一个AnchorPane中的FlowPane也可以很好地工作。
对我而言,似乎GridPanes的行为就像设置为mouseTransparent =" true",但事实并非如此,我已经尝试将其明确设置为false。我找不到这种行为的原因,所以也许你们中的某个人有一个想法。
编辑:在同一个标签中使用附加GridPane之后,我发现它不是此文件中的常规GridPane问题。对于只有复选框且只有一个Anchor的GridPane,可以访问该元素。是否存在一些阻止通过鼠标访问的重叠?在单独类的初始化函数内设置场景:
BorderPane root = FXMLLoader.load(getClass().getResource("..\\initializeSeason\\InitializeSeason.fxml"));
Scene scene = new Scene(root,600,900);
stage.setScene(scene);
stage.show();
xfml文件的构建如下(我很抱歉德语名称):
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.CheckBox?>
<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.LeagueRulesController" >
<center>
<TabPane tabClosingPolicy="UNAVAILABLE" >
<tabs>
<Tab style="-fx-font-weight:bold" text="Liga Regeln" >
<AnchorPane >
<children>
<GridPane AnchorPane.topAnchor="10.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" hgap="15" vgap="15" >
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" />
</columnConstraints>
<children>
<Label text="Anzahl der Zeichen im Teamnamen: " GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TextField fx:id="numberOfShortNameChars" alignment="BASELINE_RIGHT" prefWidth="100" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
<Label text="Anzahl der Touchdown Differenz Einträge: " GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<TextField fx:id="numberOfTDDiffEntries" alignment="BASELINE_RIGHT" prefWidth="100" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<GridPane fx:id="tdDiffEntrys" hgap="15" vgap="15" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Erhält Gewinnerteam bei Spielaufgabe maximale Punktzahl?:" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<CheckBox fx:id="isConcedeMaxWin" GridPane.columnIndex="1" GridPane.rowIndex="3"></CheckBox>
</children>
</GridPane>
<FlowPane orientation="HORIZONTAL" alignment="BOTTOM_RIGHT" hgap="5" AnchorPane.topAnchor="10.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0">
<Button fx:id="okButton" text="OK" onAction="#handleOK"> </Button>
<Button fx:id="abbrechenButton" text="Abbrechen" onAction="#handleAbbrechen"> </Button>
</FlowPane>
</children>
</AnchorPane>
</Tab>
<Tab style="-fx-font-weight:bold" text="Teams verwalten">
</Tab>
</tabs>
</TabPane>
</center>
</BorderPane>
虽然我确定可以在.fxml文件中找到问题,但我还添加了LeagueRulesController类。
package application;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class LeagueRulesController implements Initializable{
private ArrayList<TextField> tdDiffs;
private ArrayList<TextField> points;
@FXML
private CheckBox isConcedeMaxWin;
@FXML
private Button okButton;
@FXML
private Button abbrechenButton;
@FXML
private void handleAbbrechen(ActionEvent actionEvet) {
Stage stage = (Stage) abbrechenButton.getScene().getWindow();
// do what you have to do
stage.close();
}
@FXML
private void handleOK(ActionEvent actionEvet) {
Stage stage = (Stage) abbrechenButton.getScene().getWindow();
stage.close();
}
@FXML
private TextField numberOfShortNameChars;
@FXML
private TextField numberOfTDDiffEntries;
@FXML
private GridPane tdDiffEntrys;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
numberOfShortNameChars.setText("25");
numberOfShortNameChars.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
numberFieldListener(numberOfShortNameChars, oldValue,newValue);
}
});
numberOfTDDiffEntries.setText("5");
initializeTDDiffArray();
numberOfTDDiffEntries.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
numberFieldListener(numberOfTDDiffEntries, oldValue,newValue);
initializeTDDiffArray();
}
});
}
private void initializeTDDiffArray() {
tdDiffEntrys.getChildren().clear();
tdDiffs = new ArrayList<>();
points = new ArrayList<>();
tdDiffEntrys.add(new Label("TD Diff"), 0, 0);
tdDiffEntrys.add(new Label("Punkte"), 1, 0);
int numberOfTDDiffEntriesInt;
if(numberOfTDDiffEntries.getText().equals(""))
numberOfTDDiffEntriesInt = 1;
else
numberOfTDDiffEntriesInt =Integer.parseInt(numberOfTDDiffEntries.getText());
for (int i = 0; i < numberOfTDDiffEntriesInt; i++) {
tdDiffs.add(new TextField());
points.add(new TextField());
tdDiffs.get(tdDiffs.size()-1).setText(Integer.toString(i-numberOfTDDiffEntriesInt/2));
points.get(points.size()-1).setText(Integer.toString(i+1));
tdDiffs.get(tdDiffs.size()-1).setAlignment(Pos.BASELINE_RIGHT);
points.get(points.size()-1).setAlignment(Pos.BASELINE_RIGHT);
tdDiffs.get(tdDiffs.size()-1).setPrefWidth(1);
points.get(points.size()-1).setPrefWidth(1);
tdDiffs.get(tdDiffs.size()-1).textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
numberFieldListener(tdDiffs.get(tdDiffs.size()-1), oldValue,newValue);
}
});
points.get(points.size()-1).textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
numberFieldListener(points.get(points.size()-1), oldValue,newValue);
}
});
tdDiffEntrys.add(tdDiffs.get(tdDiffs.size()-1), 0, i+1);
tdDiffEntrys.add(points.get(points.size()-1), 1, i+1);
}
}
private void numberFieldListener(TextField textField, String oldValue,String newValue) {
if(!newValue.matches("\\d*")) {
textField.setText(newValue.replaceAll("[^\\d]", ""));
}
}
}
提前致谢,花时间。
答案 0 :(得分:0)
您的ALTER PROCEDURE [dbo].[Get_Station_Utilisation]
@From NVARCHAR(50),
@To NVARCHAR(50)
AS
IF @From='' SET @From = NULL
IF @To='' SET @To = NULL
SELECT T.StationID As [Station ID], dbo.Stations.StationName As [Station Name], T.StaffWorking As [Workers], T.Mins
FROM
(SELECT StatsID As StationID, [Count] As StaffWorking, SUM(Duration) AS Mins
FROM
(SELECT dbo.Active_Clockings.StationID AS StatsID, COUNT(*) AS [Count], DATEDIFF(Minute, Times2.Time, Times1.Time) AS Duration
FROM
(SELECT ROW_NUMBER() OVER (ORDER BY [Time] ASC) AS rownum, [Time]
FROM
(SELECT DISTINCT (dbo.Active_Clockings.StartTime) AS [Time]
FROM dbo.Active_Clockings
UNION
SELECT DISTINCT (dbo.Active_Clockings.FinishTime) AS [Time]
FROM dbo.Active_Clockings) AS AllTimes
) AS Times1 JOIN
(SELECT ROW_NUMBER() OVER (ORDER BY [Time] ASC) AS rownum, [Time]
FROM
(SELECT DISTINCT (dbo.Active_Clockings.StartTime) AS [Time]
FROM dbo.Active_Clockings
UNION
SELECT DISTINCT (dbo.Active_Clockings.FinishTime) AS [Time]
FROM dbo.Active_Clockings) AS AllTimes
) AS Times2 ON Times1.rownum = Times2.rownum + 1 JOIN
dbo.Active_Clockings ON Times1.Time > dbo.Active_Clockings.StartTime AND Times2.Time < dbo.Active_Clockings.FinishTime
AND (@From IS NULL OR (dbo.Active_Clockings.FinishTime > CAST(@From as date)))
AND (@To IS NULL OR dbo.Active_Clockings.FinishTime < DATEADD(Day, 1, CAST(@To as date)))
GROUP BY Times1.rownum, Times2.Time, Times1.Time, dbo.Active_Clockings.StationID) AS Totals
GROUP BY [Count], StatsID
) AS T INNER JOIN
dbo.Stations ON T.StationID= dbo.Stations.ID
ORDER BY T.StationID, T.StaffWorking ASC
位于SELECT
( LTRIM(SUBSTRING(resource.name, CHARINDEX(',', resource.name) + 1, LENGTH(resource.name) - CHARINDEX(',', resource.name)))) AS firstname,
(SELECT GROUP_CONCAT(SUBSTRING(REPLACE(resource.name, '*Deleted*', '') FROM 1 FOR POSITION(',' IN REPLACE(resource.name, '*Deleted*', '' ))-1))) AS lastname,
(SELECT GROUP_CONCAT(obj SEPARATOR ', ') FROM rel_raci resource_raci_r WHERE resource_raci_r.PERSON_ID = resource.id AND resource_raci_r.RACI ='R' AND getOrgtype(obj_id) = 6 ) AS companycode,
(SELECT GROUP_CONCAT(REPLACE(obj, '*Deleted*', '')) FROM rel_raci resource_raci_r WHERE resource_raci_r.PERSON_ID = resource.id AND resource_raci_r.RACI ='R' AND getOrgtype(obj_id) = 4 ) AS organizationalunit,
(SELECT GROUP_CONCAT(obj SEPARATOR ', ') FROM rel_raci resource_raci_r WHERE resource_raci_r.RACI ='R' ) AS responsible,
resource.identifier AS identifier,
resource.phone AS phone,
organisation.keywords AS keywords,
resource.keywords AS persno,
resource.id AS obj_id,
resource.mobile AS mobile,
resource.e_mail AS email,
resource.alias AS alias,
resource.city AS city,
resource.postcode AS postcode,
resource.state AS state,
resource.street AS street,
resource.country AS country
FROM obj_resource resource
LEFT OUTER JOIN rel_raci resource_raci ON resource.ID = resource_raci.PERSON_ID
LEFT OUTER JOIN obj_resource organisation on organisation.ID = resource_raci.OBJ_ID
-- Gibt nur die markierten Massnahmen aus
WHERE CONTAINS($P{TE_SELECTIONS}, resource.id, -1)
之上,可阻止鼠标事件到达FlowPane
。在您的FXML文件中, GridPane
和GridPane
的{{1}}约束设置为10(顶部,左侧,底部和右侧)。这意味着两个节点占用AnchorPane
中的相同空间。自从您添加GridPane
秒后,FlowPane
就会被覆盖。请注意,添加AnchorPane
秒很可能会让您点击FlowPane
,但会阻止您点击GridPane
。
而不是GridPane
为什么不使用像VBox
这样的东西? TextField
用于垂直布置节点。您也可以将Button
替换为HBox
,因为这似乎是您之后的行为。你最终会得到类似的东西:
AnchorPane
为简洁起见省略了属性。你显然将它们设置为你想要的值。
如果你走这条路线,你需要将VBox
- 文本设置为FlowPane
的那个 - 移动到新的<Tab>
<VBox>
<GridPane>
<!-- your GirdPane children -->
</GridPane>
<HBox>
<!-- your buttons -->
</HBox>
</VBox>
</Tab>
作为第一个孩子。这样它就与按钮保持一致。
当然,您没有来替换Label
。如果你想保留它,你必须弄清楚如何让"Erhält Gewinnerteam bei Spielaufgabe maximale Punktzahl?:"
的顶部锚点始终等于HBox
的底部距离顶部的距离。由于您目前拥有AnchorPane
的顶级锚点,因此FlowPane
的顶级锚点必须类似于GridPane
。我不确定你是否可以在FXML文件中执行此操作,这意味着您必须在控制器的初始化方法中执行此操作。如果您的应用程序可以调整大小,则可能还需要在调整大小时更新顶部锚点。