我在javafx2.2中偶然发现了Comboboxes的一个问题.这是场景:
此窗格包含6个组合框.其中三个有固定项:cboReport,cboSales,cboSend.其中三个从db(ObservableList)获取数据,并在窗格变为可见时填充:cboFile,cboCustomer,cboVet
窗口关闭时,窗格上的数据将通过resetGUI_editFilePane()方法重置.有像这样的行:
...
cboReport.getSelectionModel().clearSelection();
cboSales.getSelectionModel().clearSelection();
cboSend.getSelectionModel().clearSelection();
cboFile.getSelectionModel().clearSelection();
cboCustomer.getSelectionModel().clearSelection();
cboVet.getSelectionModel().clearSelection();
cboFile.getItems().clear();
cboCustomer.getItems().clear();
cboVet.getItems.clear();
...
Run Code Online (Sandbox Code Playgroud)
当用户通过按下"editFile"按钮再次打开窗格时,我注意到只有"固定项目"组合框已经清除了它们的选择,动态填充的组合框显示最后选择的项目,尽管选择本身的值是null.这看起来像是一个图形错误或我做错了什么?
有没有解决这个问题的方法或重置组合框的最佳方法是什么?
编辑2014/08/27:
这是正式的错误(clearSelection()不清楚值):https:
//bugs.openjdk.java.net/browse/JDK-8097244
官方的"解决方法"是清除选择后清除ComboBox的值.
cb.getSelectionModel().clearSelection();
// Clear value of ComboBox because clearSelection() does not do it
cb.setValue(null);
Run Code Online (Sandbox Code Playgroud) 我有一个模型和两个视图设置如下:
Model ---> OSortFilterProxyModel ---> OListView
Model ------------------------------> OTableView
Run Code Online (Sandbox Code Playgroud)
当用户在其中一个视图中选择某些内容时,我希望另一个视图镜像该选择.所以我想我会使用QSelectionModel将它们链接在一起.但这不起作用.我有一种感觉,因为观点认为它们有两种不同的模型,实际上它们具有相同的模型.有没有办法让这个工作?
当使用TableBuilder创建行和亚行,如预期选择模型不能正常工作.单击子视图的复选框时,未选择该行,但是,将选择父行.
我尝试过载onBrowserEvent的CheckboxCell,以人工处理的选择,但似乎在DataGrid本身按checkboxcell时触发选择事件.
如果行和子行来自相同类型,如何添加支持行和子行的选择模型?
我需要取消JTable模型对象中的所有选择.Java提供了这个函数"clearSelection()",根据我的理解,这就是我所需要的.
但我很困惑为什么可以在JTable对象以及JTable对象的选择模型上调用此函数:
1) mytable.clearSelection();
2) mytable.getSelectionModel().clearSelection();
Run Code Online (Sandbox Code Playgroud)
两种方式都有效,但我不明白在什么情况下,SelectionModel的clearSelection()(如2))会有任何意义.据我了解SelectionModels,它们用于决定JTable允许的选择类型.我使用SelectionModel只允许选择一行
//allow only one row to be selected
mytable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Run Code Online (Sandbox Code Playgroud)
哪种方式在哪种情况下首选?是否有充分的理由不使用方式1?
如果有人对此有一些初学友好的解释,我会很高兴.Thx提前.
我有一个带复选框选择模型的网格.
Ext.define('Mb.view.ship.OrdersGrid', {
extend: 'Ext.grid.Panel',
selType: 'checkboxmodel',
selModel: {
injectCheckbox: 0,
pruneRemoved: false
},
...
Run Code Online (Sandbox Code Playgroud)
根据字段中的值,有些行不可选择.
在普通列中,我可以renderer使用css(metadata.tdCls)干预显示和隐藏单元格内容,但对于自动生成的复选框列,我找不到一种方法来禁用或隐藏行的复选框.
有谁知道如何做到这一点?
我有一个在其模板中呈现 mat-table 的组件。我想预先选择一些行。我的 SelectionModel 包含代表每个选定项目的对象(不是简单的字符串或数字),并且比较这些对象的方法比本机 SelectionModel 的方法更复杂。
如果这是一个垫选择表单控件,我可以使用 [compareWith] 指令来提供自定义比较函数,例如
<mat-select [compareWith]="myCompareFunction" >...
Run Code Online (Sandbox Code Playgroud)
但这不是合适的解决方案 - 因为我需要表格演示。我密切关注 Angular 文档中的示例。这里的mat-table 示例:每行都有一个带有选择复选框的 mat-table,这是我遵循的方法。
在示例的组件代码中,它使用 SelectionModel 对象。
import {SelectionModel} from '@angular/cdk/collections';
....
....
selection = new SelectionModel<PeriodicElement>(true, []);
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种为 SelectionModel 对象提供自定义比较函数的方法。SelectionModel 是否可以通过函数的重写进行子类化,或者可以以某种方式“注入”方法吗?
我尝试对 SelectionModel 进行子类化并声明一个新的 CompareWith 函数,但这似乎不是所需要的。有人可以建议吗?
import { SelectionModel } from '@angular/cdk/collections';
import { InputOptionIf } from '../formosa-interfaces/dynamic-field-config-if';
export class ModalSelectSelectionModel extends SelectionModel<InputOptionIf>{
compareWith(o1:any,o2:any) {
console.log("ModalSelectSelectionModel.compareWith()")
return( <InputOptionIf>o1.label==<InputOptionIf>o2.label);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在研究 angular selectionmodel,其中我有一个搜索栏,用户可以在其中搜索列表并选择项目,如果用户关闭搜索关键字,则是先前选择的值,即在搜索未在 selectionmodel 列表中被选中之前。
在 ts 中搜索代码:
searchUsers(filterValue: string) {
this.previousSelectedValues = this.userSelection.selected;
console.log("came to searchUsers",filterValue);
this.searchKey = filterValue;
let params = { 'searchData': this.searchKey}
this.commCenterService.getSearchedUsers(params).subscribe((res)=>{
console.log("Search Response: Users",res);
this.users = res;
console.log("previous selected fields",this.userSelection.selected);
if(filterValue == ""){
this.previousSelectedValues.forEach(row => this.userSelection.select(row));
}
this.dataSource = new MatTableDataSource(this.users);
});
}
Run Code Online (Sandbox Code Playgroud)
selectionmodel 初始化代码:
userSelection = new SelectionModel<AddRecipientsList>(true, []);
/** Whether the number of selected elements matches the total number of rows. */
isAllSelected() {
const numSelected = this.userSelection.selected.length;
const numRows …Run Code Online (Sandbox Code Playgroud) 我不明白之间的差别multiple_selection_interval,并single_interval_selection在JTable.
table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
Run Code Online (Sandbox Code Playgroud)
接下来是
table.setSelectionMode(ListSelectionModel.MULTIPLE_SELECTION_INTERVAL);
Run Code Online (Sandbox Code Playgroud)
这些有什么区别?
当我们从同一行中选择时,设置为侦听单元格选择事件的JTable不生成事件,如果我选择除所选单元格以外的其他行,则Jtable触发事件.
这是代码...例如,当我选择单元格"row0 col0",然后尝试选择同一行中的任何其他单元格时,jtable将不会触发任何事件,以便在"row 0 col 1"上触发事件单元格,我必须选择第2行中的任何单元格,并且必须单击"row 0 col1"单元格
public class test_jtable_event extends javax.swing.JFrame {
/** Creates new form test_jtable_event */
public test_jtable_event() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"row 0 column1", "row 0column 2", "row 0 column 3", "row 0column4"},
{"row 1 column 0", "row 1 column 2", "row 1 column 2", "row 1 column 2"},
{null, null, null, …Run Code Online (Sandbox Code Playgroud) 我有一个jtable与listselectionlistener我可以动态添加新行到我的表,当我选择行所选行内容将出现在文本框中我能够编辑和删除数据,为我的应用程序我存储表将数据导入xml文件,当我添加新行时,将成功添加到表中.但当我选择一行并更新意味着表没有得到更新(这里我称之为加载表()).(但更新的值在xml文件中正确更改)这是我创建表的示例代码*
ListSelectionModel selectionModel;
JTable table1;
model = new DefaultTableModel();
table = new JTable(model); table.setRowHeight(20);
selectionModel = table.getSelectionModel();
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
stxtBox.setText("");
ptxtBox.setText("");
ntxtBox.setText("");
if (!e.getValueIsAdjusting()) {
model1 = table.getSelectionModel();
int lead = model1.getLeadSelectionIndex();
int columns = table.getColumnCount();
String sip = "";
String sport = "";
String snoq = "";
for (int col = 0; col < columns; col++) {
Object o = table.getValueAt(lead, col);
if (col == 0) {
sip += o.toString();
stxtBox.setText(sip);
selectedip …Run Code Online (Sandbox Code Playgroud) 我想从FXML设置TableView的SelectionModel,但我找不到如何做到这一点.我已经尝试过以下方法:
1.只需将其设置为TableView的属性:
<TableView selectionModel="MULTIPLE">
Run Code Online (Sandbox Code Playgroud)
2.设置与ListView相同的属性(请参阅:https://community.oracle.com/thread/2315611?start = 0&tstart = 0):
<TableView multiSelect="true">
Run Code Online (Sandbox Code Playgroud)
3.以不同的方式设置属性:
<TableView>
<selectionModel>
<TableView fx:constant="MULTIPLE" />
</selectionModel>
</TableView>
Run Code Online (Sandbox Code Playgroud)
4.另一个版本:
<TableView>
<selectionModel>
<SelectionModel fx:constant="MULTIPLE" />
</selectionModel>
</TableView>
Run Code Online (Sandbox Code Playgroud)
5.选择模型(不同):
<TableView>
<selectionModel>
<SelectionModel selectionModel="MULTIPLE" />
</selectionModel>
</TableView>
Run Code Online (Sandbox Code Playgroud)
这些都不起作用.
任何帮助是极大的赞赏!
带有:
tableView = QTableView()
rows = [0, 1, 2]
Run Code Online (Sandbox Code Playgroud)
tableView.selectRow(0)否则tableView.selectRow(2)在这种情况下将不起作用,因为selectRow()仅选择单个行,而取消选择所有其他行。
有selectionModel().select()可用的方法。但是它接受QSelectionItems对象作为参数。我们如何声明QSelectionItem具有行号的对象?
我试图将树的选择限制为特定列。
我大量使用委托来创建自定义的每项每列行为、编辑器等。我希望我可以通过阻止事件或类似的事情从委托中以某种方式完成此操作。问题是,我认为我必须创建一个完全自定义的解决方案来模仿扩展选择。
然而,经过大量搜索和很少的示例后,听起来我想要在树视图上自定义 QItemSelectionModel 。这个假设正确吗?
如何创建一个自定义 QItemSelectionModel ,它将使用扩展选择模式,但允许我忽略或恢复选择(如果不在特定列中)。换句话说,单击另一列不应更改选择(不应选择或取消选择)
一旦我有了选择模型,我就知道如何添加它。我请求帮助实现派生类(除非这可以通过连接的信号来完成)。
我正在使用 Python,但希望得到任何帮助。
谢谢你,
[编辑:]我发现了这些类似的问题: http://lists.qt.nokia.com/pipermail/qt-interest/2010-September/027647.html
“子类 QItemSelectionModel 并重新实现两个 select 方法以获得您想要的行为。只需忽略列 > 0 的范围部分。...或者可能只是重新实现 flags() 以使项目不可选择。我不知道是否可以会有任何副作用。”
我尝试在 QTreeWidgetItem 上重新实现标志,但从未被调用:
def flags(self, index):
print index.column()
return super(DDOutlinerBaseItem, self).flags(index)
Run Code Online (Sandbox Code Playgroud)