Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

12
LINES

< > BotCompany Repo | #1003891 // autoTableWidth - some attempt at formatting table columns decently

JavaX fragment (include)

static void autoTableWidth(JTable table) {
  final TableColumnModel columnModel = table.getColumnModel();
  for (int column = 0; column < table.getColumnCount(); column++) pcall {
      int width = 50; // Min width
      for (int row = 0; row < table.getRowCount(); row++) {
          TableCellRenderer renderer = table.getCellRenderer(row, column);
          Component comp = table.prepareRenderer(renderer, row, column);
          width = Math.max(comp.getPreferredSize().width +1 , width);
      }
      columnModel.getColumn(column).setPreferredWidth(width);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003891
Snippet name: autoTableWidth - some attempt at formatting table columns decently
Eternal ID of this version: #1003891/1
Text MD5: 067b7c415dbd488624866b6b2490398c
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-29 18:05:05
Source code size: 581 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 530 / 499
Referenced in: [show references]