我在JTabbedPane中有两个JPanel。每个JPanel都有两个DatePickers。当我编写第一个JPanel时,每个DatePickers工作正常。但是,一旦我在另一个类中添加了另外两个DatePickers,前两个DatePickers就不再起作用了。当我尝试返回所选日期(使用datePicker.getValue())时,第一个类中的DatePickers返回值null。但是,后来的DatePickers运行得很好。
有谁知道为什么会这样?
BudgetTab类中的特定代码(有问题的类):
jfxpanel = new JFXPanel();
jfxpanel2 = new JFXPanel();
jfxpanel.setBounds(460, 152, 265, 40);
jfxpanel2.setBounds(460, 276, 265, 40);
Platform.runLater(new Runnable(){
@Override
public void run(){
initFX(jfxpanel);
initFX2(jfxpanel2);
}
});
budgetPanel.add(jfxpanel);
budgetPanel.add(jfxpanel2);
private void initFX(JFXPanel panel){
Scene scene = createScene();
panel.setScene(scene);
}
private void initFX2(JFXPanel panel){
Scene scene = createScene2();
panel.setScene(scene);
}
private static Scene createScene(){
Group root = new Group();
Scene scene = new Scene(root);
dp = new DatePicker();
dp.setEditable(false);
root.getChildren().add(dp);
return scene;
}
private static Scene createScene2(){
Group root = new Group();
Scene scene = new Scene(root);
dp2 = new DatePicker();
dp2.setEditable(false);
root.getChildren().add(dp2);
return scene;
}
时间轴课程中的特定代码:
startDatePanel = new JFXPanel();
startDatePanel.setForeground(panelColor);
endDatePanel = new JFXPanel();
endDatePanel.setForeground(panelColor);
Platform.runLater(new Runnable(){
@Override
public void run(){
initStartDate(startDatePanel);
initEndDate(endDatePanel);
}
});
public void initStartDate(JFXPanel panel){
Scene scene = createStartDateScene();
panel.setScene(scene);
}
private static Scene createStartDateScene(){
Group root = new Group();
Scene scene = new Scene(root);
startDatePicker = new DatePicker();
startDatePicker.setEditable(false);
root.getChildren().add(startDatePicker);
return scene;
}
public void initEndDate(JFXPanel panel){
Scene scene = createEndDateScene();
panel.setScene(scene);
}
private static Scene createEndDateScene(){
Group root = new Group();
Scene scene = new Scene(root);
endDatePicker = new DatePicker();
endDatePicker.setEditable(false);
root.getChildren().add(endDatePicker);
return scene;
}