javax.swing.table.TableColumn Java Examples

The following examples show how to use javax.swing.table.TableColumn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JDynamicTable.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void setColumnModel(DynamicTableColumnModel columnModel)
{
	if (this.dynamicColumnModel != null)
	{
		this.dynamicColumnModel.removeDynamicTableColumnModelListener(listener);
	}
	this.dynamicColumnModel = columnModel;
	columnModel.addDynamicTableColumnModelListener(listener);
	super.setColumnModel(columnModel);
	List<TableColumn> columns = columnModel.getAvailableColumns();
	menu.getItems().clear();
	if (!columns.isEmpty())
	{
		for (TableColumn column : columns)
		{
			menu.getItems().add(createMenuItem(column));
		}
		cornerButton.setVisible(true);
	}
	else
	{
		cornerButton.setVisible(false);
	}
}
 
Example #2
Source File: PDeclensionGridPanel.java    From PolyGlot with MIT License 6 votes vote down vote up
private void setupTableColumns() {
    TableColumn column = table.getColumnModel().getColumn(0);
    PCellEditor editor = new PCellEditor(false, core);
    PCellRenderer renderer = new PCellRenderer(false, core);
    editor.setBackground(Color.gray);
    renderer.setBackground(Color.lightGray);
    column.setCellEditor(editor);
    column.setCellRenderer(renderer);
    
    Enumeration<TableColumn> colIt = table.getColumnModel().getColumns();
    colIt.nextElement(); // first column is always labels
    while (colIt.hasMoreElements()) {
        TableColumn col = colIt.nextElement();
        col.setCellEditor(new PCellEditor(true, core));
        col.setCellRenderer(new PCellRenderer(true, core));
    }
}
 
Example #3
Source File: ProfilerColumnModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void hideColumn(TableColumn column, ProfilerTable table) {
    hiddenColumnWidths.put(column.getModelIndex(), column.getWidth());
    column.setMinWidth(0);
    column.setMaxWidth(0);
    
    int selected = table.getSelectedColumn();
    if (selected != -1 && getColumn(selected).equals(column)) {
        int newSelected = getPreviousVisibleColumn(selected);
        getSelectionModel().setSelectionInterval(newSelected, newSelected);
    }
            
    if (table.isSortable()) {
        ProfilerRowSorter sorter = table._getRowSorter();
        int sortColumn = sorter.getSortColumn();
        if (sortColumn == column.getModelIndex()) {
            int newSortColumn = table.convertColumnIndexToView(sortColumn);
            newSortColumn = getPreviousVisibleColumn(newSortColumn);
            sorter.setSortColumn(getColumn(newSortColumn).getModelIndex());
        }
    }
}
 
Example #4
Source File: ALTaskTextViewerPanel.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
private void rescaleTableColumns()
{
	// iterate over all columns to resize them individually
	TableColumnModel columnModel = previewTable.getColumnModel();
	for(int columnIdx = 0; columnIdx < columnModel.getColumnCount(); ++columnIdx)
	{
		// get the current column
		TableColumn column = columnModel.getColumn(columnIdx);
		// get the renderer for the column header to calculate the preferred with for the header
		TableCellRenderer renderer = column.getHeaderRenderer();
		// check if the renderer is null
		if(renderer == null)
		{
			// if it is null use the default renderer for header
			renderer = previewTable.getTableHeader().getDefaultRenderer();
		}
		// create a cell to calculate its preferred size
		Component comp = renderer.getTableCellRendererComponent(previewTable, column.getHeaderValue(), false, false, 0, columnIdx);
		int width = comp.getPreferredSize().width;
		// set the maximum width which was calculated
		column.setPreferredWidth(width);
	}
}
 
Example #5
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean fireUpdateEvent(DefaultTableModel m, TableColumn column, Object status) {
  if (status == Status.INDETERMINATE) {
    List<?> data = m.getDataVector();
    List<Boolean> l = data.stream()
        .map(v -> (Boolean) ((List<?>) v).get(targetColumnIndex))
        .distinct()
        .collect(Collectors.toList());
    boolean notDuplicates = l.size() == 1;
    if (notDuplicates) {
      boolean isSelected = l.get(0);
      column.setHeaderValue(isSelected ? Status.SELECTED : Status.DESELECTED);
      return true;
    } else {
      return false;
    }
  } else {
    column.setHeaderValue(Status.INDETERMINATE);
    return true;
  }
}
 
Example #6
Source File: LogTable.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public LogTable(JTextArea detailTextArea) {
  super();

  init();

  _detailTextArea = detailTextArea;

  setModel(new FilteredLogTableModel());

  Enumeration columns = getColumnModel().getColumns();
  int i = 0;
  while (columns.hasMoreElements()) {
    TableColumn col = (TableColumn) columns.nextElement();
    col.setCellRenderer(new LogTableRowRenderer());
    col.setPreferredWidth(_colWidths[i]);

    _tableColumns[i] = col;
    i++;
  }

  ListSelectionModel rowSM = getSelectionModel();
  rowSM.addListSelectionListener(new LogTableListSelectionListener(this));

  //setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
}
 
Example #7
Source File: Tabulator.java    From charliebot with GNU General Public License v2.0 6 votes vote down vote up
public void reloadData(Object aobj[][]) {
    dataTableModel.setData(aobj);
    columnCount = aobj[0].length;
    Object obj = null;
    Object obj1 = null;
    boolean flag = false;
    boolean flag1 = false;
    Object aobj1[] = dataTableModel.getLongestRow();
    if (aobj1 == null)
        return;
    for (int k = 0; k < visibleColumnCount; k++) {
        TableColumn tablecolumn = table.getColumnModel().getColumn(k);
        Component component = table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(null, tablecolumn.getHeaderValue(), false, false, 0, 0);
        int i = component.getPreferredSize().width;
        component = table.getDefaultRenderer(sorterTableModel.getColumnClass(k)).getTableCellRendererComponent(table, aobj1[k], false, false, 0, k);
        int j = component.getPreferredSize().width;
        tablecolumn.setPreferredWidth(Math.max(i, j));
    }

}
 
Example #8
Source File: TableUtils.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static JScrollPane createToggleButtonSelectionPane(JTable table, JTable rowheaderTable,
	JToggleButton button)
{
	rowheaderTable.setAutoCreateColumnsFromModel(false);
	// force the tables to share models
	rowheaderTable.setModel(table.getModel());
	rowheaderTable.setSelectionModel(table.getSelectionModel());
	rowheaderTable.setRowHeight(table.getRowHeight());
	rowheaderTable.setIntercellSpacing(table.getIntercellSpacing());
	rowheaderTable.setShowGrid(false);
	rowheaderTable.setFocusable(false);

	TableColumn column = new TableColumn(-1);
	column.setHeaderValue(new Object());
	column.setCellRenderer(new TableCellUtilities.ToggleButtonRenderer(button));
	rowheaderTable.addColumn(column);
	rowheaderTable.setPreferredScrollableViewportSize(new Dimension(20, 0));

	JScrollPane scrollPane = new JScrollPane();
	scrollPane.setViewportView(table);
	scrollPane.setRowHeaderView(rowheaderTable);
	return scrollPane;
}
 
Example #9
Source File: ExtendedJTableColumnFitMouseListener.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private TableColumn getResizingColumn(JTableHeader header, Point p, int column) {
	if (column == -1) {
		return null;
	}

	Rectangle r = header.getHeaderRect(column);
	r.grow(-3, 0);

	if (r.contains(p)) {
		return null;
	}

	int midPoint = r.x + r.width / 2;
	int columnIndex = 0;
	if (header.getComponentOrientation().isLeftToRight()) {
		columnIndex = (p.x < midPoint) ? column - 1 : column;
	} else {
		columnIndex = (p.x < midPoint) ? column : column - 1;
	}

	if (columnIndex == -1) {
		return null;
	}

	return header.getColumnModel().getColumn(columnIndex);
}
 
Example #10
Source File: SystemProperties.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns a JTable containing all the system properties.  This method returns a
 * table that is configured so that the user can sort the properties by clicking on the table
 * header.
 *
 * @return a system properties table.
 */
public static SortableTable createSystemPropertiesTable() {

    final SystemPropertiesTableModel properties = new SystemPropertiesTableModel();
    final SortableTable table = new SortableTable(properties);

    final TableColumnModel model = table.getColumnModel();
    TableColumn column = model.getColumn(0);
    column.setPreferredWidth(200);
    column = model.getColumn(1);
    column.setPreferredWidth(350);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
    return table;

}
 
Example #11
Source File: DataTable.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 *  Method getColumn
 *
 * @param  columnIndex
 * @return
 */
public TableColumn getColumn(int columnIndex) {
  TableColumn tableColumn;
  try {
    tableColumn = super.getColumn(columnIndex);
  } catch(Exception ex) { // return an empty column if the columnIndex is not valid.
    return new TableColumn();
  }
  String headerValue = (String) tableColumn.getHeaderValue();
  if(headerValue==null) {
    return tableColumn;
  } 
  else if(headerValue.equals(rowName)&&(tableColumn.getModelIndex()==0)) {
    tableColumn.setMaxWidth(labelColumnWidth);
    tableColumn.setMinWidth(labelColumnWidth);
    tableColumn.setResizable(false);
  }
  else {
    tableColumn.setMinWidth(minimumDataColumnWidth);
  }
  return tableColumn;
}
 
Example #12
Source File: ColumnGroup.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the dimension of this ColumnGroup.
 *
 * @param table the table the header is being rendered in
 * @return the dimension of the ColumnGroup
 */
@SuppressWarnings("unchecked")
public Dimension getSize(JTable table) {
    Component comp = renderer.getTableCellRendererComponent(
            table, getHeaderValue(), false, false, -1, -1);
    int height = comp.getPreferredSize().height;
    int width = 0;
    Iterator iter = v.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof TableColumn) {
            TableColumn aColumn = (TableColumn) obj;
            width += aColumn.getWidth();
        } else {
            width += ((ColumnGroup) obj).getSize(table).width;
        }
    }
    return new Dimension(width, height);
}
 
Example #13
Source File: Preferences.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
void apply(TableColumnModel tcm) {
     int count = Math.min(tcm.getColumnCount(), widths.length);
     for(int i = 0; i < count; i++) {
TableColumn col = tcm.getColumn(i);
col.setPreferredWidth(widths[col.getModelIndex()]);
col.setWidth(widths[col.getModelIndex()]);
     }
     
     int last = Math.min(tcm.getColumnCount(), order.length) - 1;
     int idx  = 0;
     for(int i = last; i >= 0; i--) {
for(int j = 0; j <= i; j++) {
  if(tcm.getColumn(j).getModelIndex() == order[idx]) {
    tcm.moveColumn(j, last);
    break;
  }
}
idx++;
     }
     
     installListeners(tcm);
   }
 
Example #14
Source File: ETableColumnModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** @return the column position of the hidden column or -1 if the column is not hidden */
private int removeHiddenColumn(TableColumn column, boolean doShift) {
    int hiddenIndex = -1;
    for (int i = 0; i < hiddenColumns.size(); i++) {
        if (column.equals(hiddenColumns.get(i))) {
            hiddenIndex = i;
            break;
        }
    }
    if (hiddenIndex >= 0) {
        hiddenColumns.remove(hiddenIndex);
        int hi = hiddenColumnsPosition.remove(hiddenIndex);
        if (doShift) {
            int n = hiddenColumnsPosition.size();
            for (int i = 0; i < n; i++) {
                int index = hiddenColumnsPosition.get(i);
                if (index > hi) {
                    hiddenColumnsPosition.set(i, --index);
                }
            }
        }
        return hi;
    } else {
        return -1;
    }
}
 
Example #15
Source File: SkillPointTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void initializeTable(JTable table)
{
	table.setAutoCreateColumnsFromModel(false);
	JTableHeader header = table.getTableHeader();
	TableColumnModel columns = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = header.getDefaultRenderer();
	columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false));
	columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true));
	TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false);
	remainCol.setCellRenderer(new BoldNumberRenderer());
	columns.addColumn(remainCol);
	columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false));
	table.setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
	table.setColumnModel(columns);
	table.setFocusable(false);
	header.setReorderingAllowed(false);
	header.setResizingAllowed(false);
}
 
Example #16
Source File: TableColumnModelState.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void saveColumnSettings(Element columnElement, TableColumn column) {
	TableModel tableModel = table.getUnwrappedTableModel();
	if (!(tableModel instanceof ConfigurableColumnTableModel)) {
		return;
	}

	ConfigurableColumnTableModel configurableTableModel =
		(ConfigurableColumnTableModel) tableModel;
	Settings settings = configurableTableModel.getColumnSettings(column.getModelIndex());
	if (settings == null) {
		return;
	}

	for (String name : settings.getNames()) {
		Object value = settings.getValue(name);
		if (value instanceof String) {
			addSettingElement(columnElement, name, "String", (String) value);
		}
		else if (value instanceof Long) {
			addSettingElement(columnElement, name, "Long", value.toString());
		}
		// else if (value instanceof byte[]) // we don't handle this case; OBE?
	}
}
 
Example #17
Source File: Test6505027.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Test6505027(JFrame main) {
    Container container = main;
    if (INTERNAL) {
        JInternalFrame frame = new JInternalFrame();
        frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
        frame.setVisible(true);

        JDesktopPane desktop = new JDesktopPane();
        desktop.add(frame, new Integer(1));

        container.add(desktop);
        container = frame;
    }
    if (TERMINATE) {
        this.table.putClientProperty(KEY, Boolean.TRUE);
    }
    TableColumn column = this.table.getColumn(COLUMNS[1]);
    column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));

    container.add(BorderLayout.NORTH, new JTextField());
    container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
 
Example #18
Source File: FormattingConditionsPanel.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
private void setPrefferedColumnsSize() {
    TableColumn col = table.getColumnModel().getColumn(0);
    int width = 110;
    col.setMinWidth(width);
    col.setMaxWidth(width);
    col.setPreferredWidth(width);

    col = table.getColumnModel().getColumn(1);
    width = 90;
    col.setMinWidth(width);
    col.setMaxWidth(width);
    col.setPreferredWidth(width);

    col = table.getColumnModel().getColumn(2);
    width = 200;
    col.setMinWidth(width);
    col.setMaxWidth(width);
    col.setPreferredWidth(width);

}
 
Example #19
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
private static int calcMaxWidth(JTable table) {
  int colsNum = table.getColumnModel().getColumnCount();

  int totalWidth = 0;
  for (int col = 0; col < colsNum - 1; col++) {
    TableColumn column = table.getColumnModel().getColumn(col);
    int preferred = column.getPreferredWidth();
    int width = Math.max(preferred, columnMaxWidth(table, col));
    totalWidth += width;
    column.setMinWidth(width);
    column.setMaxWidth(width);
    column.setWidth(width);
    column.setPreferredWidth(width);
  }

  totalWidth += columnMaxWidth(table, colsNum - 1);

  return totalWidth;
}
 
Example #20
Source File: BaseTableView.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void store(final Storage storage, final JTable table) {
  final TableColumnModel model = table.getTableHeader().getColumnModel();
  final int columnCount = model.getColumnCount();
  final boolean[] storedColumns = new boolean[columnCount];
  Arrays.fill(storedColumns, false);
  for (int i = 0; i < columnCount; i++) {
    final TableColumn column = model.getColumn(i);
    storage.put(widthPropertyName(i), String.valueOf(column.getWidth()));
    final int modelIndex = column.getModelIndex();
    storage.put(orderPropertyName(i), String.valueOf(modelIndex));
    if (storedColumns[modelIndex]) {
      LOG.error("columnCount: " + columnCount + " current: " + i + " modelINdex: " + modelIndex);
    }
    storedColumns[modelIndex] = true;
  }
}
 
Example #21
Source File: ColorLegendTable.java    From workcraft with MIT License 6 votes vote down vote up
public ColorLegendTable(List<Pair<Color, String>> items) {
    setModel(new TableModel(items));

    // Make the table non-editable
    setFocusable(false);
    setRowSelectionAllowed(false);
    setRowHeight(SizeHelper.getComponentHeightFromFont(getFont()));
    setDefaultRenderer(Color.class, new ColorDataRenderer());
    setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    // Make the table transparent
    setShowGrid(false);
    setOpaque(false);
    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) getDefaultRenderer(Object.class);
    renderer.setOpaque(false);

    // Set the color cells square shape
    TableColumnModel columnModel = getColumnModel();
    int colorCellSize = getRowHeight();
    TableColumn column = columnModel.getColumn(0);
    column.setMinWidth(colorCellSize);
    column.setMaxWidth(colorCellSize);
}
 
Example #22
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void setColumnCollapsed(Column column, boolean collapsed) {
    if (!getColumnControlVisible()) {
        return;
    }

    checkNotNullArgument(column, "column must be non null");

    if (column.isCollapsed() != collapsed) {
        column.setCollapsed(collapsed);
    }

    TableColumn tableColumn = getColumn(column);
    if (tableColumn instanceof TableColumnExt) {
        ((TableColumnExt) tableColumn).setVisible(!collapsed);
    }
}
 
Example #23
Source File: UIUtil.java    From rest-client with Apache License 2.0 6 votes vote down vote up
/**
* @Title      : setHistTabWidth 
* @Description: set history table width 
* @Param      : @param tab 
* @Return     : void
* @Throws     :
 */
public static void setHistTabWidth(JTable tab)
{
    int width[] = { 35, 260, 81, 144, 50, 80 };
    TableColumnModel cols = tab.getColumnModel();
    for (int i = 0; i < width.length; i++)
    {
        if (width[i] < 0)
        {
            continue;
        }

        TableColumn col = cols.getColumn(i);
        if (i == 1 || i == 4 || i == 5)
        {
            col.setMinWidth(width[i]);
            continue;
        }

        col.setMinWidth(width[i]);
        col.setMaxWidth(width[i]);
    }
}
 
Example #24
Source File: MoveChooserService.java    From Shuffle-Move with GNU General Public License v3.0 6 votes vote down vote up
/**
 * From Stackoverflow: http://stackoverflow.com/a/17627497
 * 
 * @param table
 *           The table to be resized
 */
public void resizeColumnWidth(JTable table) {
   table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   final TableColumnModel columnModel = table.getColumnModel();
   for (int column = 0; column < table.getColumnCount(); column++) {
      TableColumn tableColumn = columnModel.getColumn(column);
      TableCellRenderer r = tableColumn.getHeaderRenderer();
      if (r == null) {
         r = table.getTableHeader().getDefaultRenderer();
      }
      Component component = r.getTableCellRendererComponent(table, tableColumn.getHeaderValue(), false, false, 0,
            column);
      int width = component.getPreferredSize().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);
      }
      tableColumn.setPreferredWidth(width);
   }
}
 
Example #25
Source File: RefineryUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a panel that contains a table based on the specified table model.
 *
 * @param model  the table model to use when constructing the table.
 *
 * @return The panel.
 */
public static JPanel createTablePanel(TableModel model) {

    JPanel panel = new JPanel(new BorderLayout());
    JTable table = new JTable(model);
    for (int columnIndex = 0; columnIndex < model.getColumnCount(); 
            columnIndex++) {
        TableColumn column = table.getColumnModel().getColumn(columnIndex);
        Class c = model.getColumnClass(columnIndex);
        if (c.equals(Number.class)) {
            column.setCellRenderer(new NumberCellRenderer());
        }
    }
    panel.add(new JScrollPane(table));
    return panel;

}
 
Example #26
Source File: CheckoutsPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void create(ItemCheckoutStatus[] checkouts) {
	tableModel = new CheckoutsTableModel(checkouts);

	// set up table sorter stuff
	TableSortStateEditor tsse = new TableSortStateEditor();
	tsse.addSortedColumn(CheckoutsTableModel.DATE_COL, SortDirection.DESCENDING);
	tableModel.setTableSortState(tsse.createTableSortState());

	table = new GTable(tableModel);
	JScrollPane sp = new JScrollPane(table);
	table.setPreferredScrollableViewportSize(new Dimension(680, 120));
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	add(sp, BorderLayout.CENTER);

	TableColumnModel columnModel = table.getColumnModel();
	//MyCellRenderer cellRenderer = new MyCellRenderer();

	TableColumn column;

	column = columnModel.getColumn(CheckoutsTableModel.DATE_COL);
	column.setPreferredWidth(120);
	column.setCellRenderer(new GenericDateCellRenderer("Date when file was checked out"));
	columnModel.getColumn(CheckoutsTableModel.VERSION_COL).setPreferredWidth(50);
	columnModel.getColumn(CheckoutsTableModel.USER_COL).setPreferredWidth(80);
	columnModel.getColumn(CheckoutsTableModel.HOST_COL).setPreferredWidth(120);
	columnModel.getColumn(CheckoutsTableModel.PROJECT_NAME_COL).setPreferredWidth(120);
	columnModel.getColumn(CheckoutsTableModel.PROJECT_LOC_COL).setPreferredWidth(180);
}
 
Example #27
Source File: GroupableTableHeaderUI.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) {
  TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
  TableCellRenderer renderer = aColumn.getHeaderRenderer();
  if (renderer == null)
    renderer = header.getDefaultRenderer();
  Component component = renderer.getTableCellRendererComponent(header.getTable(),
      aColumn.getHeaderValue(), false, false, -1, columnIndex);
  rendererPane.add(component);
  rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width,
      cellRect.height, true);
}
 
Example #28
Source File: DiagnosticsForThreads.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
public DiagnosticsForThreads() {

    JTable table = new JTable(tableModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    // code added Feb 2014 by Doug Brown
  	FontSizer.setFonts(table, FontSizer.getLevel());
  	Font font = table.getFont();
  	table.setRowHeight(font.getSize()+4);
  	table.getTableHeader().setFont(font);
    // end added code

    TableColumnModel colModel = table.getColumnModel();
    int numColumns = colModel.getColumnCount();

    for (int i = 0; i < numColumns - 1; i++) {
      TableColumn col = colModel.getColumn(i);

      col.sizeWidthToFit();
      col.setPreferredWidth(col.getWidth() + 5);
      col.setMaxWidth(col.getWidth() + 5);
    }

    JScrollPane sp = new JScrollPane(table);

    setLayout(new BorderLayout());
    add(sp, BorderLayout.CENTER);
  }
 
Example #29
Source File: ModelUtils.java    From aurous-app with GNU General Public License v2.0 5 votes vote down vote up
public static void loadPlayList(final String fileLocation) {
		try {
System.out.println(fileLocation);
			table = TabelPanel.table;
			DefaultTableModel tableModel = TabelPanel.tableModel;
			final String datafile = fileLocation;
			final FileReader fin = new FileReader(datafile);

			tableModel = Csv2TableModel.createTableModel(fin, null);
			if (tableModel == null) {
				JOptionPane.showMessageDialog(null,
						"Error loading playlist, corrupted or unfinished.",
						"Error", JOptionPane.ERROR_MESSAGE);

				ModelUtils.loadPlayList("ta/scripts/blank.plist");
				PlayListPanel.canSetLast = false;
				return;
			} else {
				PlayListPanel.canSetLast = true;
			}
			table.setModel(tableModel);
			final TableColumn hiddenLink = table.getColumnModel().getColumn(
					LINK_INDEX);
			hiddenLink.setMinWidth(2);
			hiddenLink.setPreferredWidth(2);
			hiddenLink.setMaxWidth(2);
			hiddenLink.setCellRenderer(new InteractiveRenderer(LINK_INDEX));
			final TableColumn hiddenAlbumArt = table.getColumnModel()
					.getColumn(ALBUMART_INDEX);
			hiddenAlbumArt.setMinWidth(2);
			hiddenAlbumArt.setPreferredWidth(2);
			hiddenAlbumArt.setMaxWidth(2);
			hiddenAlbumArt.setCellRenderer(new InteractiveRenderer(
					ALBUMART_INDEX));

		} catch (final FileNotFoundException e) {
			System.out.println("afaafvava");
			ModelUtils.loadPlayList("data/scripts/blank.plist");
		}
	}
 
Example #30
Source File: ScrDeclensionGenClassic.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * populates transforms of currently selected rule
 */
private void populateTransforms() {
    DeclensionGenRule curRule = (DeclensionGenRule) lstRules.getSelectedValue();

    transModel = new DefaultTableModel();
    transModel.addColumn("Regex");
    transModel.addColumn("Replacement");
    tblTransforms.setModel(transModel);

    // do not populate if multiple selections
    if (lstRules.getSelectedIndices().length > 1) {
        return;
    }
    
    boolean useConFont = !core.getPropertiesManager().isOverrideRegexFont();

    TableColumn column = tblTransforms.getColumnModel().getColumn(0);
    column.setCellEditor(new PCellEditor(useConFont, core));
    column.setCellRenderer(new PCellRenderer(useConFont, core));
    
    column = tblTransforms.getColumnModel().getColumn(1);
    column.setCellEditor(new PCellEditor(useConFont, core));
    column.setCellRenderer(new PCellRenderer(useConFont, core));

    // do nothing if nothing selected in rule list
    if (curRule == null) {
        return;
    }

    DeclensionGenTransform[] curTransforms = curRule.getTransforms();

    for (DeclensionGenTransform curTrans : curTransforms) {
        Object[] newRow = {curTrans.regex, curTrans.replaceText};
        transModel.addRow(newRow);
    }

    tblTransforms.setModel(transModel);
}