javax.swing.table.TableColumn#setMinWidth ( )源码实例Demo

下面列出了javax.swing.table.TableColumn#setMinWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rest-client   文件: UIUtil.java
/**
* @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]);
    }
}
 
源代码2 项目: consulo   文件: OrderPanel.java
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);
}
 
源代码3 项目: netbeans   文件: CustomizerSources.java
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));
    }
 
源代码4 项目: mobile-persistence   文件: AttributesPanel.java
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);
  }
 
源代码5 项目: consulo   文件: ShowUsagesAction.java
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;
}
 
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);

}
 
源代码7 项目: PacketProxy   文件: GUIFilterConfig.java
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]);
		}
	}
}
 
源代码8 项目: IntelliJDeodorant   文件: MoveMethodPanel.java
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);
}
 
源代码9 项目: WePush   文件: JTableUtil.java
/**
 * 隐藏表格中的某一列
 *
 * @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);
}
 
源代码10 项目: aurous-app   文件: ModelUtils.java
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");
		}
	}
 
源代码11 项目: MobyDroid   文件: JPanel_TaskManager.java
/**
 *
 */
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);
    }
}
 
源代码12 项目: nextreports-designer   文件: DBColumnViewerPanel.java
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);
}
 
源代码13 项目: zap-extensions   文件: WebSocketMessagesView.java
/**
 * 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);
    }
}
 
源代码14 项目: snap-desktop   文件: TableViewPagePanel.java
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);
        }
    }
}
 
源代码15 项目: flutter-intellij   文件: FlutterLogView.java
private static void fixColumnWidth(@NotNull TableColumn column, int width) {
  column.setMinWidth(width);
  column.setMaxWidth(width);
  column.setPreferredWidth(width);
}
 
源代码16 项目: pdfxtk   文件: Swing.java
public static void setWidth(TableColumn column, int width) {
  column.setPreferredWidth(width);   
  column.setMinWidth(width);
  column.setMaxWidth(width);
}
 
源代码17 项目: flutter-intellij   文件: FlutterLogView.java
private static void fixColumnWidth(@NotNull TableColumn column, int width) {
  column.setMinWidth(width);
  column.setMaxWidth(width);
  column.setPreferredWidth(width);
}
 
源代码18 项目: mars-sim   文件: ColumnResizer.java
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);

        }
    }
 
源代码19 项目: bither-desktop-java   文件: ShowTransactionsForm.java
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;
    }
 
源代码20 项目: KEEL   文件: StatisticalF.java
/**
 * 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);

}