- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个可以通过按钮进行编辑的 TableView。当按下按钮时进行确认和弹出其他数据。问题通常是在收集和/或确认所有数据(例如删除一行或创建新行)之后,TableView 显示双甚至三重数据条目。附在下面。这些行无法单击。没有获得焦点。我的操作系统是 Ubuntu 16.04,我的 IDE 是 Netbeans 8.2。
package basicShit;
import allg.ObjectFilePersistence;
import allg.StringFilePersistence;
import allg.TTADAOException;
import allg.ThinxToAdminDAO;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import javafx.util.Pair;
import java.io.File;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.*;
import java.util.function.Consumer;
public class Director extends Application
{
private static ThinxToAdminDAO<Project> projectMGMT;
private static String log = "";
private static File logFilesDir = new File("/home/storm/Projekte/LogFiles");
private static final String CONTEXTFILENAME = "Contexte";
private static File contextListDir = new File("/home/storm/Projekte/Contexte");
private static String contexteFileEnd = "cntxt";
private static final String NOTETYPEFILENAME = "NoteTyps";
private static File noteListDir = new File("/home/storm/Projekte/NoteTyps");
private static String noteTypsFileEnd = "typs";
private static ButtonsTableAndTxtArea<ProjectTableViewModel> bTATA;
private final static List<String> COLUMNNAMES = Arrays.asList
("Name", "Status", "Goal");
private final static List<String> COLUMNACCESS = Arrays.asList
("name", "status", "goal");
private static Set<String> contextChoice;
private static Set<String> noteListTyps;
private final Button btnCreate = new Button("Create");
private final Button btnSave = new Button("Save");
private final Button btnReadAndUpdate = new Button("Read/Update");
private final Button btnDelete = new Button("Delete");
private final Button btnSetDataDir = new Button("Set Data Dir");
private final Button btnStats = new Button("Statistics");
private final Button btnVSG = new Button("View Step Group");
public static <S> void logIt(Pair<S, String> p)
{
String l = p.getValue() + " " + getNowTimeString();
log= log + "\n" + l;
System.out.println(l);
}
public static String getTimeString(LocalDateTime ldt)
{
ZonedDateTime nowWithTimeZone = ZonedDateTime.of
(ldt, ZoneId.of("Europe/Berlin"));
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime
(FormatStyle.FULL);
return dtf.format(nowWithTimeZone);
}
public static String getNowTimeString()
{
return getTimeString(LocalDateTime.now());
}
public static Consumer<String> alertWindow = (s)->
{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("Error");
alert.setContentText(s);
alert.setResizable(true);
alert.getDialogPane().setPrefWidth(s.length()*7+10);
alert.showAndWait();
};
public static boolean confirm(String question)
{
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setHeaderText("Confirmation");
alert.setContentText(question);
Optional<ButtonType> result = alert.showAndWait();
return (result.get().equals(ButtonType.OK));
}
private List<Button> getBtns()
{
List<Button> btnList = new ArrayList<>();
final EventHandler<ActionEvent> eHCreate = (event)->
{
Pair<Project, String> p = create();
if (p.getKey() != null)
{
try
{
projectMGMT.add(p.getKey());
writeToTable(p.getKey());
logIt(p);
}
catch(TTADAOException e)
{
System.out.println("Couldnt register Project!");
}
}
};
btnCreate.setOnAction(eHCreate);
btnList.add(btnCreate);
final EventHandler<ActionEvent> eHSave = (event)->
{
Pair<String, String> p;
try
{
p = save();
logIt(p);
}
catch(TTADAOException e)
{
System.out.println("Couldnt save it(All).");
}
};
btnSave.setOnAction(eHSave);
btnList.add(btnSave);
final EventHandler<ActionEvent>eHReadUpdate = (event)->
{
try
{
Project project =
projectMGMT.getThingByName(detectSelection().getName());
Pair<Stage, String> p = details(project);
logIt(p);
p.getKey().showAndWait();
bTATA.getObservableList().clear();
fillTable();
}
catch(TTADAOException e)
{
System.out.println("There is no Details.");
alertWindow.accept("Select Properly");
}
};
btnReadAndUpdate.setOnAction(eHReadUpdate);
btnList.add(btnReadAndUpdate);
final EventHandler<ActionEvent> eHDelete = (event)->
{
Pair<ProjectTableViewModel, String> p = delete();
try
{
if (p.getKey() != null)
{
projectMGMT.removeByName(p.getKey().getName());
bTATA.getObservableList().remove(p.getKey());
logIt(p);
}
}
catch(TTADAOException e)
{
System.out.println("Deleting went Wrong");
}
};
btnDelete.setOnAction(eHDelete);
btnList.add(btnDelete);
final EventHandler<ActionEvent> eHSetDataDir = (event)->
{
Pair<File, String> p = setDataDir();
ProjectMGMT pm = (ProjectMGMT)projectMGMT;
pm.setStandartDir(p.getKey());
logIt(p);
};
btnSetDataDir.setOnAction(eHSetDataDir);
btnList.add(btnSetDataDir);
btnStats.setOnAction(statistics);
btnList.add(btnStats);
btnVSG.setOnAction(viewStepGroup);
btnList.add(btnVSG);
return btnList;
}
public static void main(String... args)
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
TextArea info = new TextArea();
info.setEditable(false);
info.setStyle("-fx-highlight-fill: lightgray; -fx-highlight-text-fill: firebrick; -fx-font-size: 12px;");
info.setWrapText(true);
primaryStage = new
ButtonsTableAndTxtArea<>
("Got it All", getBtns(), COLUMNNAMES, COLUMNACCESS, info);
projectMGMT = new ProjectMGMT();
ObjectFilePersistence<Set<String>> ofp = new ObjectFilePersistence<>();
contextChoice = ofp.loadObject(CONTEXTFILENAME,contextListDir.toString(),contexteFileEnd);
noteListTyps = ofp.loadObject(NOTETYPEFILENAME,noteListDir.toString(),noteTypsFileEnd);
bTATA = (ButtonsTableAndTxtArea)primaryStage;
bTATA.getTableView().setOnMouseClicked(clickOnTable);
projectMGMT.loadData();
fillTable();
InputSpawns.initialize();
initializeTypsAndChoices();
InputSpawns.upDateContexte(contextChoice);
InputSpawns.upDateNoteTitels(noteListTyps);
btnBindings();//Must be done after bTATA is ready
primaryStage.show();
}
public void btnBindings()
{
//Thru the bind these Buttons are only available when
//a Row in the TableView is selected!!!
btnReadAndUpdate.disableProperty().bind(bTATA.getTableView().getSelectionModel().selectedItemProperty().isNull());
btnDelete.disableProperty().bind(bTATA.getTableView().getSelectionModel().selectedItemProperty().isNull());
}
public static void initializeTypsAndChoices()
{
noteListTyps = new HashSet<>();
noteListTyps.addAll(ProjectNote.typs);
contextChoice = new HashSet<>();
contextChoice.addAll(Step.contextChoice);
}
private static void writeToTable(Project project)
{
String name = project.getName();
String status = project.getLastNxtStp().getStatus();
String goal = project.getGoal();
ProjectTableViewModel pTVM = new ProjectTableViewModel(name, status, goal);
bTATA.getObservableList().add(pTVM);
}
public static Pair<String, String> save() throws TTADAOException
{
projectMGMT.saveData();
return new Pair(null, "All Saved");
}
public static ProjectTableViewModel detectSelection()
{
return bTATA.getTableView().getSelectionModel().getSelectedItem();
}
public Pair<Stage, String> details(Project project)
{
Stage stage = new DetailStage(project, log);
String s = "Detail Stage opened for Project "+project.getName()+".";
return new Pair(stage, s);
}
public static Pair<ProjectTableViewModel, String> delete()
{
ProjectTableViewModel pTVM = detectSelection();
if(pTVM!=null)
{
String name = pTVM.getName();
boolean q = confirm("Are you sure u want to delete Project "+name+" ??");
if(q)return new Pair(pTVM, "Project: "+name+" deleted.");
else return new Pair(null, "Project Deletion aborted.");
}
else return new Pair(null, "Didnt choose a Project to Delete.");
}
public EventHandler<ActionEvent> viewStepGroup = (event)->
{
};
public Pair<File, String> setDataDir()
{
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Choose Data Directory");
directoryChooser.setInitialDirectory(new File("/home"));
File file = directoryChooser.showDialog(null);//Owner Window is null
Pair<File, String> re;
String s;
if(file==null)s="Data Dir Not Changed!";
else s="Data Dir set to: "+file.getAbsolutePath();
return new Pair(file, s);
}
public EventHandler<ActionEvent> statistics = (event)->
{
};
public EventHandler<MouseEvent> clickOnTable = (event)->
{
ProjectTableViewModel pTVM = detectSelection();
String prjctName="";
if(pTVM!=null)
{
try
{
//Todo: Make it colored Text txt = new Text();
prjctName = pTVM.getName();
bTATA.setInfoText(projectMGMT.getThingByName(prjctName).toString());
}
catch (TTADAOException e)
{
System.out.println("Couldnt get a Project with name "+prjctName+".");
}
}
};
public static Pair<Project,String> create()
{
Optional<Project> project = InputSpawns.projectSpawn();
if(project.isPresent())
{
return new Pair(project.get(), "Project: "+project.get().getName()+" created.");
}
else
{
System.out.println("Project creation failed.");
return new Pair(null, "Project creation failed.");
}
}
public void fillTable()
{
projectMGMT.getThingNames().forEach((name) -> {
try
{
Project p = projectMGMT.getThingByName(name);
writeToTable(p);
}
catch(TTADAOException e)
{
System.out.println("Couldnt get A Project with name "+name+".");
}
});
}
@Override
public void stop()
{
try
{
Pair<String, String> p = save();
logIt(p);
}
catch(TTADAOException e)
{
System.out.println("Couldnt save it(All).");
}
String t = getNowTimeString();
StringFilePersistence.saveString("Log File Project Action" + t, logFilesDir.toString(), log);
ObjectFilePersistence<Set<String>> ofp = new ObjectFilePersistence<>();
ofp.saveObject(CONTEXTFILENAME,contextListDir.toString(),contexteFileEnd,contextChoice);
ofp.saveObject(NOTETYPEFILENAME,noteListDir.toString(),"typs",noteListTyps);
}
}
我也用这个方法:
public static <M> TableView<M> tableSetup(ObservableList<M> data, List<String> columns, List<String> columnAccess, int[] columnWidth)
{
TableView<M> tv = new TableView<>();
int n = columns.size();
int widthSum = 0;
TableColumn<M,String>[] tColumns = new TableColumn[n];
for(int i=0;i<n;i++)
{
tColumns[i] = new TableColumn<M, String>(columns.get(i));
final int width = columnWidth[i];
tColumns[i].setPrefWidth(columnWidth[i]);
tColumns[i].setCellValueFactory(new PropertyValueFactory<>(columnAccess.get(i)));
widthSum = widthSum+ columnWidth[i];
tv.getColumns().add(tColumns[i]);
tColumns[i].setCellFactory(column->
{
return new TableCell<M, String>()
{
@Override
protected void updateItem(String item, boolean empty)
{
super.updateItem(item, empty);
if (item == null || empty)
{
setText(null);
setStyle("");
}
else
{
Text txt = new Text(item);
txt.setWrappingWidth(width-7);
setGraphic(txt);
}
}
};
});
}
tv.setPrefWidth(widthSum);
tv.setItems(data);
return tv;
}
谢谢,我期待学习新东西。问候 xylo。
最佳答案
您使用 TextField
作为 TableCell
的图形
来显示内容,但您设置了Text
属性为 null
。这样图形
就永远不会被删除。但您需要这样做,因为单元格可能会变空:
tColumns[i].setCellFactory(column -> new TableCell<M, String>() {
private final Text txt = new Text();
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty){
setGraphic(null);
} else {
txt.setText(item);
txt.setWrappingWidth(width-7);
setGraphic(txt);
}
}
});
关于通过按钮编辑时,JavaFX TableView 的行为很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50766528/
我正在对 tableView 是否呈现单元格进行单元测试。 我发现 tableView.cellForRow(at:) 返回 nil,而 tableView.dataSource?tableView(
我有 Tableview 用于显示客户下的食品订单。其中包含水平 UIStackview。在 UIStackView UIStackview 中很少有一/两行标签和一个用于显示订单项的UITableV
我有 Viewcontroller,我在其中设置了 ScrollView 。在 scrollview 中,我有一个 tableview,它位于 Container 中,就在容器下方,当我将 table
我想在滚动时让我的第一个单元格始终位于 tableview 的顶部。 任何帮助都是可观的。提前致谢... 最佳答案 这是为 UITableView 创建标题 View 的方法 - (UIView *)
在我的应用程序中,我点击一行,它会在其下方展开另一行。我想生成一种随机颜色,当我单击一行时,行背景会变成该颜色,而它下面的展开行会变成相同的颜色。如何让行生成相同的随机颜色? 我创建了一个函数来生成随
我正在为这个问题苦苦挣扎,所以我需要你的帮助。基本上我已经编写了一个复杂的 TableView Controller (使用 NSFetchedResults 协议(protocol)等)并且已经在我
我正在使用 JavaFx 2.2。我遇到了一个问题,我无法在 TableView 列中放置不同的组件。例如我有两列 1) 回答 2) 答案类型 如果 AnswerType 包含“Multiple Ch
试图弄清楚如何在 javafx 2 中禁用表列的重新排序? 最佳答案 这是解决方案: tblView.getColumns().addListener(new ListChangeListener()
我一直在寻找有关将数据刷新到 tableview 的信息。我试图直接修改模型,但我遇到了一个错误。我修改了模型,但表格没有刷新,只有当我移动一列时,表格才会显示修改后的值。 为了给你展示一个例子(13
给定一个TableView,我需要检测单元格上的双击。 tableView.setOnMouseClicked(new EventHandler() { @Override publi
我成功创建了一个 TableView,其中将特定列分配给了数据模型类。该程序可以将 csv 文件解析为其中并在表中正确显示所有内容。在此阶段,滚动不是问题。 然后我想选择特定行并将它们发送到另一个表。
我尝试了所有方法来用数据填充 TableView。下一个代码在表中插入一个新行,但数据没有出现在表中。我试图为此找到解释,但没有成功。 请帮忙。我不知道怎么了。 在 controller.java 中
我尝试了所有方法来用数据填充 TableView。下一个代码在表中插入一个新行,但数据没有出现在表中。我试图为此找到解释,但没有成功。 请帮忙。我不知道怎么了。 在 controller.java 中
我有一个通过 Tableview 显示玩家的应用程序。用户可以“添加”一个新玩家并输入他的姓名、高度、体重、图片等...保存后将被添加到 Tableview 中。他们还可以点击每个玩家,然后将他们带到
对于大学,我必须编写一个小应用程序,其想法是创建一个小公式集合。这个概念是有一个类别列表,选择类别后您会收到一个公式列表。选择所需的公式后,您将看到公式计算器的 View 。 我正在努力获得第一个UI
如果我只加载一个 TableView ,我的 View 中必须有两个 TableView ,它工作正常。但是当我尝试使用下面的方法加载两个表格 View 时,它给出了以下异常。 未捕获异常“NSRan
我是 JavaFx 的新手,我正在尝试创建一个 TableView ,而 fxml 是使用场景生成器创建的。如果我运行该程序,该表不会获取值。我发现这个问题在某种程度上符合我的要求( javaFX 2
是否可以对 tableView 进行反向排序?我搜索了很多解决方案,但没有任何效果。 效果就像whatsapp聊天。 一个普通的tableView是: ---------- label 1 -----
我有一个有趣的问题。我有两个 TableView ,一个在另一个里面。我有一个结构,我想用它来将数据添加到我的 TableView 中。该结构有 2 个字符串项和另一个具有 3 个字符串项的结构的数组
我正在使用的方法 func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath
我是一名优秀的程序员,十分优秀!