Package javax.swing.table

Examples of javax.swing.table.DefaultTableColumnModel


    protected TableModel createDefaultDataModel() {
        return new DefaultTableModel();
    }

    protected TableColumnModel createDefaultColumnModel() {
        return new DefaultTableColumnModel();
    }
View Full Code Here


        super(name);
    }

    @Override
    protected void setUp() throws Exception {
        event = new TableColumnModelEvent(new DefaultTableColumnModel(), 5, 10);
    }
View Full Code Here

    public void testTableColumnModelEvent() throws Exception {
        assertTrue(event.getSource() instanceof DefaultTableColumnModel);
        assertEquals(5, event.getFromIndex());
        assertEquals(10, event.getToIndex());
        event = new TableColumnModelEvent(new DefaultTableColumnModel(), 10, 5);
        assertEquals(10, event.getFromIndex());
        assertEquals(5, event.getToIndex());
    }
View Full Code Here

        JTable activityTable = new JTable(tableModel);
        activityTable.setDefaultRenderer(Message.class, new MessageCellRenderer());
        activityTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

        DefaultTableColumnModel defaultColumn = (DefaultTableColumnModel) activityTable.getColumnModel();

        getContentPane().add(new JScrollPane(activityTable));

        Point point = serverMonitor.getMainMonitorGUI().getLocation();
        setLocation(point.x + 20, point.y + 20);
        setSize(500, 300);

        defaultColumn.getColumn(0).setResizable(false);
        defaultColumn.getColumn(0).setPreferredWidth(120);
        defaultColumn.getColumn(0).setMaxWidth(120);

        setVisible(true);

        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
View Full Code Here

    Point point = serverMonitor.getMainMonitorGUI().getLocation();
    setLocation(point.x + 20, point.y + 20);
    setSize(500, 300);

    DefaultTableColumnModel defaultColumn = (DefaultTableColumnModel) activityTable.getColumnModel();

    defaultColumn.getColumn(0).setResizable(false);
    defaultColumn.getColumn(0).setPreferredWidth(120);
    defaultColumn.getColumn(0).setMaxWidth(120);

    defaultColumn = (DefaultTableColumnModel) detailsTable.getColumnModel();
    defaultColumn.getColumn(0).setPreferredWidth(120);
    defaultColumn.getColumn(0).setMaxWidth(250);

    setVisible(true);

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
View Full Code Here

     * @param col    column index
     * @param margin column side margin
     */
    public static void packColumnWidth ( final JTable table, final int col, final int margin )
    {
        final DefaultTableColumnModel columnModel = ( DefaultTableColumnModel ) table.getColumnModel ();
        final TableColumn column = columnModel.getColumn ( col );
        int width;

        // Header renderer
        TableCellRenderer renderer = column.getHeaderRenderer ();
        if ( renderer == null )
View Full Code Here

   * @param width the new width
   */
  public void setColWidth( int columnIdx, int width
  {
    if ( isShowing() && isVisible()) {
      DefaultTableColumnModel colModel = (DefaultTableColumnModel)getColumnModel();
      TableColumn column = colModel.getColumn( columnIdx );
      column.setMaxWidth( width );
    }
    else {
      try {
        final int w = width;
        final int col = columnIdx;
        SwingUtilities.invokeLater( new Runnable() {
          public void run()
          {
            /**
             * This is intended to be called after the component is displayed,
             * so rthis delay may not work. Some die effects can be caused by
             * the L&F delegate resetting properties and therefore whatever
             * calls this probably shouldn't call this method till after
             * addNotify is called.
             */
            DefaultTableColumnModel colModel = (DefaultTableColumnModel)getColumnModel();
            TableColumn column = colModel.getColumn( col );
            column.setMaxWidth( w );
          }
        });
      }
      catch ( Exception e ) {}
View Full Code Here

    }
   
    private void initTableProperties(String sql) {
     
        CacheTableModel tm = new CacheTableModel(object, sql, stat);
        TableColumnModel rowHeaderModel = new DefaultTableColumnModel() {
            boolean first = true;           
            public void addColumn(TableColumn tc) {
                if (first) {
                    super.addColumn(tc);
                    first = false;
                }
            }           
        };
        headerColumn.setModel(tm);
        headerColumn.setColumnModel(rowHeaderModel);
        headerColumn.createDefaultColumnsFromModel();
        headerColumn.setEnabled(false);
        TableColumn indexColumn = headerColumn.getColumnModel().getColumn(0);
        indexColumn.setCellRenderer(new IndexRenderer());
        indexColumn.setMinWidth(50);
        indexColumn.setResizable(false);
        headerColumn.setGridColor(Color.LIGHT_GRAY);
        headerColumn.setRowHeight(18);
        table.setRowHeight(18);
        table.setGridColor(Color.LIGHT_GRAY);
       
        TableColumnModel cm = new DefaultTableColumnModel() {
            boolean first = true;           
            public void addColumn(TableColumn tc) {
                if (first) {
                    first = false;
                    return;
                }
                tc.setResizable(true);               
                super.addColumn(tc);
            }           
        };
        table.setModel(tm);
        table.setColumnModel(cm);
        table.createDefaultColumnsFromModel();
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);       
        for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
            TableColumn column = table.getColumnModel().getColumn(i);
            String columnName = (String)column.getHeaderValue();
            if (sortStates.get(columnName) == null)
                column.setHeaderRenderer(new SortRenderer(null, -1));
        }
        for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
            TableColumn tcolumn = table.getColumnModel().getColumn(i);
            //String columnName = (String)tcolumn.getHeaderValue();           
            //fort report table
            if (((String)tm.getTables().get(i)).trim().length() <= 0) {
                String name = (String)tm.getColumns().get(i);
                String value = null;
                StringTokenizer st = new StringTokenizer(name, "_");
                st.nextElement();
                String tableName = (String)st.nextElement();
                String columnName = (String)st.nextElement();         
                Column column = ObjectUtil.findColumn(object, tableName, columnName);
                if (column != null)
                    value = column.toString();
                else
                    value = tableName + "_" + columnName;
                if (name.indexOf("SUM_") > -1)
                    tcolumn.setHeaderRenderer(new ImageRenderer("SUM(" + value + ")", ImageManager.getImage(ImageManager.SUM_IMAGE)));
                else if (name.indexOf("COUNT_") > -1)
                    tcolumn.setHeaderRenderer(new ImageRenderer("COUNT(" + value + ")", ImageManager.getImage(ImageManager.COUNT_IMAGE)));
            }                       
        }
        try {
            for (int i = 1; i < tm.getColumnCount(); i++) {
                if (tm.getRs().getMetaData().getColumnDisplaySize(i) == 6)
                    cm.getColumn(i - 1).setPreferredWidth(150);
                else if (tm.getRs().getMetaData().getColumnDisplaySize(i) >= 256)
                    cm.getColumn(i -1).setPreferredWidth(100);
                else
                    cm.getColumn(i - 1).setMinWidth(tm.getRs().getMetaData().getColumnDisplaySize(i) * 5);
                cm.getColumn(i - 1).setMaxWidth(200);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        int n = 0;
View Full Code Here

     * @param margin the margin to add
     * @return the preferred width of the column
     */
    public int getPreferredColumnWidth(JTable table, int colIndex, int margin) {

        DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
        TableColumn col = colModel.getColumn(colIndex);

        // get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();
        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
View Full Code Here

     *
     * @return the preferred width of the column
     */
    public static Integer getPreferredAccessionColumnWidth(JTable table, int colIndex, int margin, Integer maxProteinKeyLength) {

        DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
        TableColumn col = colModel.getColumn(colIndex);

        // get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();
        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
View Full Code Here

TOP

Related Classes of javax.swing.table.DefaultTableColumnModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.