簡體   English   中英

Java SWT表單元比較

[英]Java SWT table cells comparing

我正在使用SWT開發GUI。 該軟件獲取txt文件並將所有數據推送到表中。 是否可以在一行中的每個單元格上運行以比較單元格? 並遍歷表格中的每一行來執行此操作。

我不明白如果只有.getColumnCount()怎么.getColumnCount()

還有一件事:是否可以突出顯示不同的單元格?

編輯:

                        for (int loopIndexPM1ColumnTools = 0; loopIndexPM1ColumnTools < tableConfigurationSystemColumnLP.size(); loopIndexPM1ColumnTools++) {
                        TableColumn column = new TableColumn(tableConfigurationLP, SWT.NONE, loopIndexPM1ColumnTools);
                        column.setWidth(100);
                        column.setText(tableConfigurationSystemColumnLP.get(loopIndexPM1ColumnTools));
                      }

                    /*
                     * Loop for adding items to each column in CE-LP Tab
                     */
                      for (int loopIndexPM1ColumnTools = 0; loopIndexPM1ColumnTools < CE_LP_Parameter.size(); loopIndexPM1ColumnTools++) {
                        TableItem item = new TableItem(tableConfigurationLP, SWT.NONE);
                        item.setText(0, CE_LP_Parameter.get(loopIndexPM1ColumnTools));
                        item.setText(1, CE_LP1_Value.get(loopIndexPM1ColumnTools));
                        item.setText(2, CE_LP2_Value.get(loopIndexPM1ColumnTools));
                        item.setText(3, CE_LP3_Value.get(loopIndexPM1ColumnTools));

                      }

                      for (int loopIndexPM1ColumnTools = 0; loopIndexPM1ColumnTools < tableConfigurationSystemColumnLP.size(); loopIndexPM1ColumnTools++) {
                          tableConfigurationLP.getColumn(loopIndexPM1ColumnTools).pack();
                      }

編輯:

                          int tbl_clm = tableConfigurationLP.getColumnCount();
                      int tbl_rows = tableConfigurationLP.getItemCount();
                      for(int i=0;i<tbl_clm;i++) {
                          for(int x=0;x<tbl_rows;x++) {
                              System.out.println(tableConfigurationLP.getColumn(i).getText());
                          }
                      }

Table

  • getItemCount()為您提供行數
  • getItem(rowIndex)獲取行rowIndex處的TableItem
  • getItems()獲得所有TableItem
  • getColumnCount()獲取列數

TableItem具有

  • getText(colIndex)獲取列colIndex的文本

因此,例如:

Table table = .... the table

int rows = table.getItemCount();
int columns = table.getColumnCount();

for (int rowIndex = 0; rowIndex < rows; ++rowIndex) {
   TableItem rowItem = table.getItem(rowIndex);

   for (int colIndex = 0; colIndex < columns; ++colIndex) {
       String colValue = rowItem.getText(colIndex);

       ....
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM