コード例 #1
0
 private static void drawSelection(JTable table, int column, Graphics g, final int width) {
   int y = 0;
   final int[] rows = table.getSelectedRows();
   final int height = table.getRowHeight();
   for (int row : rows) {
     final TableCellRenderer renderer = table.getCellRenderer(row, column);
     final Component component =
         renderer.getTableCellRendererComponent(
             table, table.getValueAt(row, column), false, false, row, column);
     g.translate(0, y);
     component.setBounds(0, 0, width, height);
     boolean wasOpaque = false;
     if (component instanceof JComponent) {
       final JComponent j = (JComponent) component;
       if (j.isOpaque()) wasOpaque = true;
       j.setOpaque(false);
     }
     component.paint(g);
     if (wasOpaque) {
       ((JComponent) component).setOpaque(true);
     }
     y += height;
     g.translate(0, -y);
   }
 }
コード例 #2
0
    public void tableChanged(TableModelEvent evt) {
      int row, col;
      String key, val;

      if (evt.getType() == TableModelEvent.UPDATE) {
        row = evt.getFirstRow();
        col = evt.getColumn();
        if (col == 0) { // set()
          key = (String) table_model.getValueAt(row, col);
          val = (String) table_model.getValueAt(row, col + 1);
          if (key != null && val != null) {
            tree.put(selected_node, key, val);
          }
        } else { // add()
          key = (String) table_model.getValueAt(row, col - 1);
          val = (String) table.getValueAt(row, col);
          if (key != null && val != null) {
            tree.put(selected_node, key, val);
          }
        }
      }
    }