Java Code Examples for javax.swing.table.TableColumn#setMinWidth()

The following examples show how to use javax.swing.table.TableColumn#setMinWidth() . 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: 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 2
Source File: ShowUsagesAction.java    From consulo 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 3
Source File: AttributesPanel.java    From mobile-persistence with MIT License 6 votes vote down vote up
public void createAttributesTable(DataObjectInfo doi) {
      table = new GenericTable(new AttributeTableModel(doi));
      table.setColumnSelectorAvailable(false);
    table.getSelectionModel().addListSelectionListener(this);
    //To stop cell editing when user switches to another component without using tab/enter keys
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

//      TableCellRenderer checkBoxRenderer = new TableCellCheckBoxRenderer();
//      TableCellCheckBoxEditor checkBoxEditor = new TableCellCheckBoxEditor();

    TableColumn tc0 = table.getColumnModel().getColumn(0);
    tc0.setMinWidth(55);
    tc0.setMaxWidth(55);
    TableColumn tc1 = table.getColumnModel().getColumn(1);
    tc1.setMinWidth(40);
    tc1.setMaxWidth(40);
    TableColumn tc2 = table.getColumnModel().getColumn(2);
    tc2.setMinWidth(70);
    tc2.setMaxWidth(70);
    scrollPane.getViewport().setView(table);
    TableColumn tc5 = table.getColumnModel().getColumn(5);
    ClassPickerTextButtonCellEditor editor = new ClassPickerTextButtonCellEditor(new Context(null, ProjectUtils.getViewControllerProject()),this );
    tc5.setCellEditor(editor);
  }
 
Example 4
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 5
Source File: CustomizerSources.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void initTableVisualProperties(JTable table) {

        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        table.setIntercellSpacing(new java.awt.Dimension(0, 0));
        // set the color of the table's JViewport
        table.getParent().setBackground(table.getBackground());
        
        //we'll get the parents width so we can use that to set the column sizes.
        double pw = table.getParent().getParent().getPreferredSize().getWidth();
        
        //#88174 - Need horizontal scrollbar for library names
        //ugly but I didn't find a better way how to do it
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        TableColumn column = table.getColumnModel().getColumn(0);
        column.setMinWidth(226);
        column.setWidth( ((int)pw/2) - 1 );
        column.setPreferredWidth( ((int)pw/2) - 1 );
        column.setMinWidth(75);
        column = table.getColumnModel().getColumn(1);
        column.setMinWidth(226);
        column.setWidth( ((int)pw/2) - 1 );
        column.setPreferredWidth( ((int)pw/2) - 1 );
        column.setMinWidth(75);
        this.addComponentListener(new TableColumnSizeComponentAdapter(table));
    }
 
Example 6
Source File: OrderPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void setCheckboxColumnName(final String name) {
  final int width;
  if (StringUtil.isEmpty(name)) {
    CHECKBOX_COLUMN_NAME = "";
    width = new JCheckBox().getPreferredSize().width;
  }
  else {
    CHECKBOX_COLUMN_NAME = name;
    final FontMetrics fontMetrics = myEntryTable.getFontMetrics(myEntryTable.getFont());
    width = fontMetrics.stringWidth(" " + name + " ") + 4;
  }

  final TableColumn checkboxColumn = myEntryTable.getColumnModel().getColumn(getCheckboxColumn());
  checkboxColumn.setWidth(width);
  checkboxColumn.setPreferredWidth(width);
  checkboxColumn.setMaxWidth(width);
  checkboxColumn.setMinWidth(width);
}
 
Example 7
Source File: GUIFilterConfig.java    From PacketProxy with Apache License 2.0 5 votes vote down vote up
private void tableFixedColumnWidth(JTable table, int[] menu_width, boolean[] fixed_map) {
	for (int index = 0; index < fixed_map.length; index++) {
		if (fixed_map[index]) {
			TableColumn col = table.getColumnModel().getColumn(index);
			col.setMinWidth(menu_width[index]);
			col.setMaxWidth(menu_width[index]);
		}
	}
}
 
Example 8
Source File: TableViewPagePanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
void setModel(TableModel tableModel) {
    table.setModel(tableModel);
    if (table.getColumnCount() > 0) {
        final JTableHeader tableHeader = table.getTableHeader();
        final int margin = tableHeader.getColumnModel().getColumnMargin();
        final TableCellRenderer renderer = tableHeader.getDefaultRenderer();
        final Enumeration<TableColumn> columns = table.getColumnModel().getColumns();
        while (columns.hasMoreElements()) {
            TableColumn tableColumn = columns.nextElement();
            final int width = getColumnMinWith(tableColumn, renderer, margin);
            tableColumn.setMinWidth(width);
        }
    }
}
 
Example 9
Source File: WebSocketMessagesView.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method for setting the column widths of this view.
 *
 * @param index
 * @param min
 * @param preferred
 */
protected void setColumnWidth(int index, int min, int preferred) {
    TableColumn column = view.getColumnModel().getColumn(index);

    if (min != -1) {
        column.setMinWidth(min);
    }

    if (preferred != -1) {
        column.setPreferredWidth(preferred);
    }
}
 
Example 10
Source File: DBColumnViewerPanel.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
private void setPrefferedColumnsSize() {
    TableColumn col = table.getColumnModel().getColumn(0);
    int width = 20;
    col.setMinWidth(width);
    col.setMaxWidth(width);
    col.setPreferredWidth(width);

    col = table.getColumnModel().getColumn(1);
    width = 160;
    col.setPreferredWidth(width);

    col = table.getColumnModel().getColumn(2);
    width = 120;
    col.setPreferredWidth(width);

    col = table.getColumnModel().getColumn(3);
    width = 80;
    col.setPreferredWidth(width);

    col = table.getColumnModel().getColumn(4);
    width = 80;
    col.setPreferredWidth(width);

    col = table.getColumnModel().getColumn(5);
    width = 80;
    col.setPreferredWidth(width);
}
 
Example 11
Source File: JPanel_TaskManager.java    From MobyDroid with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
private void setColumnWidth(int column, int minWidth, int maxWidth) {
    TableColumn tableColumn = jTable_Tasks.getColumnModel().getColumn(column);
    if (minWidth >= 0 && maxWidth >= 0) {
        tableColumn.setPreferredWidth((minWidth + maxWidth) / 2);
    }
    if (minWidth >= 0) {
        tableColumn.setMinWidth(minWidth);
    }
    if (maxWidth >= 0) {
        tableColumn.setMaxWidth(maxWidth);
    }
}
 
Example 12
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 13
Source File: JTableUtil.java    From WePush with MIT License 5 votes vote down vote up
/**
 * 隐藏表格中的某一列
 *
 * @param table
 * @param index
 */
public static void hideColumn(JTable table, int index) {
    TableColumn tableColumn = table.getColumnModel().getColumn(index);
    tableColumn.setMaxWidth(0);
    tableColumn.setMinWidth(0);
    tableColumn.setPreferredWidth(0);
    tableColumn.setWidth(0);

    table.getTableHeader().getColumnModel().getColumn(index).setMaxWidth(0);
    table.getTableHeader().getColumnModel().getColumn(index).setMinWidth(0);
}
 
Example 14
Source File: MoveMethodPanel.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
private void setupTableLayout() {
    final TableColumn selectionColumn = table.getTableHeader().getColumnModel().getColumn(SELECTION_COLUMN_INDEX);
    selectionColumn.setMaxWidth(30);
    selectionColumn.setMinWidth(30);

    final TableColumn dependencies = table.getTableHeader().getColumnModel().getColumn(SELECTION_COLUMN_INDEX);
    dependencies.setMaxWidth(30);
    dependencies.setMinWidth(30);
}
 
Example 15
Source File: ColumnResizer.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public static void adjustColumnPreferredWidths(JTable table) {

        // Gets max width for cells in column as the preferred width
        TableColumnModel columnModel = table.getColumnModel();
        for (int col=0; col<table.getColumnCount(); col++) {
            // System.out.println ("--- col " + col + " ---");
            int maxwidth = 40;
            //int minwidth = 40;
            int colWidth = 0;
            for (int row=0; row<table.getRowCount(); row++) {
                TableCellRenderer rend = table.getCellRenderer (row, col);
//                Object value = table.getValueAt (row, col);
//                Component comp =
//                    rend.getTableCellRendererComponent (table,
//                                                        value,
//                                                        false,
//                                                        false,
//                                                        row,
//                                                        col);

                Component comp = table.prepareRenderer(rend, row, col);
                colWidth = comp.getPreferredSize().width;
                //minwidth = colWidth;
                //if (colWidth > maxwidth) maxwidth = colWidth;
                //if (colWidth < minwidth) minwidth = colWidth;
                maxwidth = Math.max (colWidth, maxwidth);
                //minwidth = Math.max (colWidth, minwidth);

                //System.out.println ("col " + col +
                //                    " pref width now " +
                //                    maxwidth);
            }

            // Considers the column header's preferred width too
            TableColumn column = columnModel.getColumn (col);

//            int headerWidth = 0;
//            TableCellRenderer headerRenderer = column.getHeaderRenderer();
//            if (headerRenderer == null)
//                headerRenderer = table.getTableHeader().getDefaultRenderer();
//            Object headerValue = column.getHeaderValue();
//            Component headerComp =
//                    headerRenderer.getTableCellRendererComponent (table,
//                                                                  headerValue,
//                                                                  false,
//                                                                  false,
//                                                                  0,
//                                                                  col);
//            headerWidth = headerComp.getPreferredSize().width;
//
//            maxwidth = Math.max (colWidth, headerWidth);
//            minwidth = Math.min (colWidth, headerWidth);

            column.setPreferredWidth (maxwidth);
            //column.setMaxWidth(maxwidth); // very bad!
            column.setMinWidth(maxwidth);

        }
    }
 
Example 16
Source File: FlutterLogView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void fixColumnWidth(@NotNull TableColumn column, int width) {
  column.setMinWidth(width);
  column.setMaxWidth(width);
  column.setPreferredWidth(width);
}
 
Example 17
Source File: Swing.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
public static void setWidth(TableColumn column, int width) {
  column.setPreferredWidth(width);   
  column.setMinWidth(width);
  column.setMaxWidth(width);
}
 
Example 18
Source File: FlutterLogView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void fixColumnWidth(@NotNull TableColumn column, int width) {
  column.setMinWidth(width);
  column.setMaxWidth(width);
  column.setPreferredWidth(width);
}
 
Example 19
Source File: ShowTransactionsForm.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
private JPanel createTransactionsPanel() {
        JPanel transactionsPanel = new JPanel();
        transactionsPanel.setMinimumSize(new Dimension(550, 160));
        transactionsPanel.setBackground(Themes.currentTheme.detailPanelBackground());
        transactionsPanel.setLayout(new GridBagLayout());
        transactionsPanel.setOpaque(true);
        GridBagConstraints constraints = new GridBagConstraints();

        txTableModel = new TxTableModel(txList);
        table = new JTable(txTableModel);
        table.setOpaque(false);
        table.setBorder(BorderFactory.createEmptyBorder());
        table.setComponentOrientation(ComponentOrientation.getOrientation(LocaliserUtils.getLocale()));
        table.setRowHeight(Math.max(BitherSetting.MINIMUM_ICON_HEIGHT, panelMain.getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont()).getHeight()) + BitherSetting.HEIGHT_DELTA);

        // Use status icons.
        table.getColumnModel().getColumn(0).setCellRenderer(new ImageRenderer(ShowTransactionsForm.this));
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setRowSelectionAllowed(true);
        table.setColumnSelectionAllowed(false);
        table.setBackground(Themes.currentTheme.detailPanelBackground());

        // No row is currently selected.
        selectedRow = -1;

        // Listener for row selections.
        listSelectionModel = table.getSelectionModel();
        listSelectionModel.addListSelectionListener(new SharedListSelectionHandler(showTransactionDetailsAction));

        // Date right justified.
        table.getColumnModel().getColumn(1).setCellRenderer(new TrailingJustifiedDateRenderer(ShowTransactionsForm.this));

        // Justify column headers.
        justifyColumnHeaders();

//        // Description leading justified (set explicitly as it does not seem to work otherwise).
//        if (ComponentOrientation.getOrientation(LocaliserUtils.getLocale()).isLeftToRight()) {
//            table.getColumnModel().getColumn(2).setCellRenderer(new LeadingJustifiedRenderer(ShowTransactionsForm.this));
//        } else {
//            table.getColumnModel().getColumn(2).setCellRenderer(new TrailingJustifiedStringRenderer(ShowTransactionsForm.this));
//        }

        // Amount decimal aligned
        DecimalAlignRenderer decimalAlignRenderer = new DecimalAlignRenderer(ShowTransactionsForm.this);
        table.getColumnModel().getColumn(2).setCellRenderer(decimalAlignRenderer);


        FontMetrics fontMetrics = panelMain.getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());
        TableColumn tableColumn = table.getColumnModel().getColumn(0); // status
        int statusWidth = fontMetrics.stringWidth(LocaliserUtils.getString("walletData.statusText"));
        tableColumn.setPreferredWidth(statusWidth + BitherSetting.STATUS_WIDTH_DELTA);

        tableColumn = table.getColumnModel().getColumn(1); // Date.


        int dateWidth = Math.max(fontMetrics.stringWidth(LocaliserUtils.getString("walletData.dateText")),
                fontMetrics.stringWidth(DateUtils.getDateTimeString(new Date(DateUtils.nowUtc().getMillis()))));
        tableColumn.setPreferredWidth(dateWidth);

        tableColumn = table.getColumnModel().getColumn(2); // Amount (BTC).
        int amountBTCWidth = Math.max(fontMetrics.stringWidth(LocaliserUtils.getString("sendBitcoinPanel.amountLabel") + " (BTC)"),
                fontMetrics.stringWidth("00000.000000000"));
        tableColumn.setPreferredWidth(amountBTCWidth);
        tableColumn.setMinWidth(amountBTCWidth);

        // Row sorter.
        rowSorter = new TableRowSorter<TableModel>(table.getModel());
        table.setRowSorter(rowSorter);

        // Sort by date descending.
        List<TableRowSorter.SortKey> sortKeys = new ArrayList<TableRowSorter.SortKey>();
        sortKeys.add(new TableRowSorter.SortKey(1, SortOrder.DESCENDING));
        rowSorter.setSortKeys(sortKeys);


        rowSorter.setComparator(1, dateComparator);
        rowSorter.setComparator(2, comparatorNumber);


        scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        scrollPaneSetup();

        showTransactionDetailsAction.setEnabled(table.getSelectedRow() > -1);

        constraints.fill = GridBagConstraints.BOTH;
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridwidth = 1;
        constraints.weightx = 1;
        constraints.weighty = 1;

        transactionsPanel.add(scrollPane, constraints);

        return transactionsPanel;
    }
 
Example 20
Source File: StatisticalF.java    From KEEL with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Builder
 */
public StatisticalF() {

    this.setResizable(true);

    TableColumn column;

    initComponents();

    lastPath=".";

    testType = FRIEDMAN;
    objective = MAXIMIZE;

    model = new statTableModel();

    editor = new StatCellEditor();

    renderer = new statTableRenderer();
    model.initComponents();

    dataTable.setCellEditor(editor);
    dataTable.setDefaultRenderer(Double.class, renderer);

    dataTable.setModel(model);

    for (int i = 0; i < dataTable.getColumnModel().getColumnCount(); i++) {
        column = dataTable.getColumnModel().getColumn(i);
        if (i == 0) {
            column.setPreferredWidth(80); //first column is bigger
            column.setMinWidth(80);
        } else {
            column.setPreferredWidth(75);
            column.setMinWidth(75);
        }
    }

    this.content.muestraURL(this.getClass().getResource("/help/stat/stat_help.html"));

    ExcelAdapter myAd = new ExcelAdapter(dataTable);

    //set frame icon
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(StatisticalF.class.getResource("/keel/GraphInterKeel/resources/ico/logo/logo.gif")));

    //set the form visible
    this.setVisible(true);

}