我正在努力在网格上显示数据库中的数据并且到目前为止工作正常。我想添加编辑功能,但它确实有效,但我努力使其仅适用于某些列,而不是其他列。
这是当前的代码:
/// <summary>
/// Returns the max visible line count of a UI.Text component. The text's vertical
/// overflow must be set to truncate or this method will return 0.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static int GetMaxLineCount(Text text)
{
if (text == null || text.verticalOverflow != VerticalWrapMode.Truncate) return 0;
var textBackup = text.text;
var lineCount = 0;
text.text = "";
while (true)
{
text.text += "\n";
Canvas.ForceUpdateCanvases();
var nextLineCount = text.cachedTextGenerator.lineCount;
if (lineCount == nextLineCount) break;
lineCount = nextLineCount;
}
text.text = textBackup;
return lineCount;
}
如上所示,编辑器显示所有字段。对于这种情况,我只希望值字段可以编辑。我尝试将SettingJpaController sc
= new SettingJpaController(Lookup.getDefault()
.lookup(DatabaseManager.class)
.getEntityManagerFactory());
Grid<Setting> settings = new Grid<>();
TextField value = new TextField();
settings.getEditor().setEnabled(true);
settings.setItems(sc.findSettingEntities());
settings.addColumn(Setting::getSettingName)
.setCaption("Name");
settings.addColumn(setting -> setting.getSettingValue())
.setCaption("Value")
.setEditorComponent(value, Setting::setSettingValue)
.setExpandRatio(1);
settings.getEditor().addSaveListener((EditorSaveEvent<Setting> event) -> {
try {
sc.edit(event.getBean());
} catch (Exception ex) {
LOG.log(Level.SEVERE, null, ex);
}
});
settings.addColumn(Setting::getDescription).setCaption("Description");
添加到其他列,但我收到此错误:
.setEditable(false)
对我来说没有必要分配和编辑等等只是为了禁用它所以我确定我错过了什么。有什么想法吗?