Example usage for javax.swing JTable AUTO_RESIZE_NEXT_COLUMN

List of usage examples for javax.swing JTable AUTO_RESIZE_NEXT_COLUMN

Introduction

In this page you can find the example usage for javax.swing JTable AUTO_RESIZE_NEXT_COLUMN.

Prototype

int AUTO_RESIZE_NEXT_COLUMN

To view the source code for javax.swing JTable AUTO_RESIZE_NEXT_COLUMN.

Click Source Link

Document

When a column is adjusted in the UI, adjust the next column the opposite way.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
    String[] columnNames = { "col1", "col2" };

    JTable table = new JTable(cellData, columnNames);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
}

From source file:MainClass.java

public static void main(String args[]) {
    String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    String headers[] = { "Upper", "Lower" };

    final int modeKey[] = { JTable.AUTO_RESIZE_ALL_COLUMNS, JTable.AUTO_RESIZE_LAST_COLUMN,
            JTable.AUTO_RESIZE_NEXT_COLUMN, JTable.AUTO_RESIZE_OFF, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS };

    final JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    String modes[] = { "Resize All Columns", "Resize Last Column", "Resize Next Column", "Resize Off",
            "Resize Subsequent Columns" };

    final JComboBox resizeModeComboBox = new JComboBox(modes);
    int defaultMode = 4;
    table.setAutoResizeMode(modeKey[defaultMode]);
    resizeModeComboBox.setSelectedIndex(defaultMode);
    ItemListener itemListener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            int index = resizeModeComboBox.getSelectedIndex();
            table.setAutoResizeMode(modeKey[index]);
        }/*ww  w.  j  a  v a2s  .  co m*/
    };
    resizeModeComboBox.addItemListener(itemListener);

    JFrame frame = new JFrame("Resizing Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(resizeModeComboBox, BorderLayout.NORTH);
    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:ResizeTable.java

public static void main(String args[]) {

    final Object rowData[][] = { { "1", "one", "I" }, { "2", "two", "II" }, { "3", "three", "III" } };
    final String columnNames[] = { "#", "English", "Roman" };

    final JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);

    String modes[] = { "Resize All Columns", "Resize Last Column", "Resize Next Column", "Resize Off",
            "Resize Subsequent Columns" };

    final int modeKey[] = { JTable.AUTO_RESIZE_ALL_COLUMNS, JTable.AUTO_RESIZE_LAST_COLUMN,
            JTable.AUTO_RESIZE_NEXT_COLUMN, JTable.AUTO_RESIZE_OFF, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS };

    JComboBox resizeModeComboBox = new JComboBox(modes);

    ItemListener itemListener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            JComboBox source = (JComboBox) e.getSource();
            int index = source.getSelectedIndex();
            table.setAutoResizeMode(modeKey[index]);
        }/*from w w w  . j a  v a2s  . co m*/
    };
    resizeModeComboBox.addItemListener(itemListener);

    JFrame frame = new JFrame("Resizing Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(resizeModeComboBox, BorderLayout.NORTH);
    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:ResizeTable.java

public static void main(String args[]) {

    Object rowData[][] = { { "1", "one", "ichi - \u4E00", "un", "I" },
            { "2", "two", "ni - \u4E8C", "deux", "II" }, { "3", "three", "san - \u4E09", "trois", "III" },
            { "4", "four", "shi - \u56DB", "quatre", "IV" }, { "5", "five", "go - \u4E94", "cinq", "V" },
            { "6", "six", "roku - \u516D", "treiza", "VI" }, { "7", "seven", "shichi - \u4E03", "sept", "VII" },
            { "8", "eight", "hachi - \u516B", "huit", "VIII" }, { "9", "nine", "kyu - \u4E5D", "neur", "IX" },
            { "10", "ten", "ju - \u5341", "dix", "X" } };

    String columnNames[] = { "#", "English", "Japanese", "French", "Roman" };

    final JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);

    String modes[] = { "Resize All Columns", "Resize Last Column", "Resize Next Column", "Resize Off",
            "Resize Subsequent Columns" };
    final int modeKey[] = { JTable.AUTO_RESIZE_ALL_COLUMNS, JTable.AUTO_RESIZE_LAST_COLUMN,
            JTable.AUTO_RESIZE_NEXT_COLUMN, JTable.AUTO_RESIZE_OFF, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS };
    JComboBox resizeModeComboBox = new JComboBox(modes);
    int defaultMode = 4;
    table.setAutoResizeMode(modeKey[defaultMode]);
    resizeModeComboBox.setSelectedIndex(defaultMode);
    ItemListener itemListener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            JComboBox source = (JComboBox) e.getSource();
            int index = source.getSelectedIndex();
            table.setAutoResizeMode(modeKey[index]);
        }/*from  w ww . ja  va 2 s  .co m*/
    };
    resizeModeComboBox.addItemListener(itemListener);

    JFrame frame = new JFrame("Resizing Table");
    Container contentPane = frame.getContentPane();

    contentPane.add(resizeModeComboBox, BorderLayout.NORTH);
    contentPane.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:com.openbravo.pos.sales.JTicketLines.java

/** Creates new form JLinesTicket */
public JTicketLines(AppView app, String propertyRowHeight, String propertyFontsize, String ticketline) {
    this.m_App = app;
    initComponents();/*from   ww w . j a v a 2 s.co  m*/

    m_jTicketTable.m_App = app;
    m_jTicketTable.propertyRowHeight = propertyRowHeight;

    ColumnTicket[] acolumns = new ColumnTicket[0];

    if (ticketline != null) {
        try {
            if (m_sp == null) {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                m_sp = spf.newSAXParser();
            }
            ColumnsHandler columnshandler = new ColumnsHandler();
            m_sp.parse(new InputSource(new StringReader(ticketline)), columnshandler);
            acolumns = columnshandler.getColumns();

        } catch (ParserConfigurationException ePC) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.parserconfig"), ePC);
        } catch (SAXException eSAX) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.xmlfile"), eSAX);
        } catch (IOException eIO) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.iofile"), eIO);
        }
    }

    Map<String, Integer> widths = PropertyUtil.getTicketLineWidths(m_App);
    for (ColumnTicket acolumn : acolumns) {
        Integer width = widths.get(acolumn.name);
        if (width == null) {
            continue;
        }
        acolumn.width = width;
    }

    m_jTableModel = new TicketTableModel(acolumns);
    m_jTicketTable.setModel(m_jTableModel);

    m_jTicketTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    TableColumnModel jColumns = m_jTicketTable.getColumnModel();
    for (int i = 0; i < acolumns.length; i++) {
        jColumns.getColumn(i).setPreferredWidth(acolumns[i].width);
        jColumns.getColumn(i).setResizable(true);
    }

    PropertyUtil.ScaleScrollbar(m_App, m_jScrollTableTicket);

    m_jTicketTable.getTableHeader().setReorderingAllowed(false);
    // m_jTicketTable.setDefaultRenderer(Object.class, new
    // TicketCellRenderer(app, acolumns, propertyFontsize));
    m_jTicketTable.setDefaultRenderer(Object.class,
            new RowHeightCellRenderer(app, acolumns, propertyFontsize, propertyRowHeight));

    PropertyUtil.ScaleTableColumnFontsize(m_App, m_jTicketTable, "sales-tablecolumn-fontsize", "14");

    m_jTicketTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    m_jTicketTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JTable table = (JTable) me.getSource();
            Point p = me.getPoint();
            int row = table.rowAtPoint(p);
            if (me.getClickCount() == 2) {
                // your valueChanged overridden method
                listDoubleClickListener.valueChanged(new ListSelectionEvent(m_jTicketTable, row, row, false));
            }
        }
    });
    // reseteo la tabla...
    m_jTableModel.clear();
}

From source file:org.kuali.test.ui.base.BaseTable.java

/**
 *
 * @param config/* www .  j  av a 2s  . c  o m*/
 */
public BaseTable(TableConfiguration config) {
    super(new BaseTableModel(config));

    for (int i = 0; i < config.getHeaders().length; ++i) {
        int cx = getColumnWidth(i);
        getColumnModel().getColumn(i).setWidth(cx);
        getColumnModel().getColumn(i).setPreferredWidth(cx);
    }

    getTableHeader().setReorderingAllowed(false);
    setShowHorizontalLines(true);
    setShowVerticalLines(true);
    setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

    popupMenu = new JPopupMenu();
    JMenuItem m;
    popupMenu.add(m = new JMenuItem(Constants.COPY_ACTION));
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(new StringSelection(celldata), BaseTable.this);
            celldata = null;
        }
    });

    MouseAdapter ma = new MouseAdapter() {
        private void myPopupEvent(MouseEvent e) {
            int col = BaseTable.this.columnAtPoint(e.getPoint());
            int row = BaseTable.this.rowAtPoint(e.getPoint());
            if ((col > -1) && (row > -1)) {
                if (BaseTable.this.getValueAt(row, col) != null) {
                    celldata = BaseTable.this.getValueAt(row, col).toString();
                    popupMenu.show(BaseTable.this.getComponentAt(e.getX(), e.getY()), e.getX(), e.getY());
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                myPopupEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                myPopupEvent(e);
            }
        }
    };

    addMouseListener(ma);

    initializing = false;
}

From source file:org.zaproxy.zap.extension.httppanel.view.paramtable.HttpPanelParamTableView.java

private void initAddins() {
    // Get all addins
    addins = new LinkedList<>();
    addins.add(new ParamAddinMagic());
    addins.add(new ParamAddinUrlencode());

    comboBoxAddIns = new JComboBox<>();
    comboBoxAddIns.addItem(ADD_INS);//from  w ww.j  a  va  2  s .c  o m
    for (ParamAddinInterface addin : addins) {
        comboBoxAddIns.addItem(addin);
    }
    comboBoxAddIns.addActionListener(new ComboBoxAddinsActionListener());

    table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(getComboBoxTypes()));

    table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

    if (table.getColumnCount() != 4) {
        return;
    }

    table.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBoxAddIns));
    table.getColumnModel().getColumn(3).setCellRenderer(new ComboBoxCellRenderer(comboBoxAddIns));
}

From source file:org.zaproxy.zap.extension.httppanelviews.paramtable.HttpPanelParamTableView.java

private void initAddins() {
    // Get all addins
    addins = new LinkedList<ParamAddinInterface>();
    addins.add(new ParamAddinMagic());
    addins.add(new ParamAddinUrlencode());

    comboBoxAddIns = new JComboBox();
    comboBoxAddIns.addItem(ADD_INS);/*from   w w  w.  ja  va2s .c  o m*/
    for (ParamAddinInterface addin : addins) {
        comboBoxAddIns.addItem(addin);
    }
    comboBoxAddIns.addActionListener(new ComboBoxAddinsActionListener());

    table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(getComboBoxTypes()));

    table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

    if (table.getColumnCount() != 4) {
        return;
    }

    table.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBoxAddIns));
    table.getColumnModel().getColumn(3).setCellRenderer(new ComboBoxCellRenderer(comboBoxAddIns));
}

From source file:pl.otros.logview.gui.LogViewPanel.java

private JPopupMenu initTableContextMenu() {
    JPopupMenu menu = new JPopupMenu("Menu");
    JMenuItem mark = new JMenuItem("Mark selected rows");
    mark.addActionListener(new MarkRowAction(otrosApplication));
    JMenuItem unmark = new JMenuItem("Unmark selected rows");
    unmark.addActionListener(new UnMarkRowAction(otrosApplication));

    JMenuItem autoResizeMenu = new JMenu("Table auto resize mode");
    autoResizeMenu.setIcon(Icons.TABLE_RESIZE);
    JMenuItem autoResizeSubsequent = new JMenuItem("Subsequent columns");
    autoResizeSubsequent//  ww  w. ja v  a  2s .  com
            .addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS));
    JMenuItem autoResizeLast = new JMenuItem("Last column");
    autoResizeLast.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_LAST_COLUMN));
    JMenuItem autoResizeNext = new JMenuItem("Next column");
    autoResizeNext.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_NEXT_COLUMN));
    JMenuItem autoResizeAll = new JMenuItem("All columns");
    autoResizeAll.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_ALL_COLUMNS));
    JMenuItem autoResizeOff = new JMenuItem("Auto resize off");
    autoResizeOff.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_OFF));
    autoResizeMenu.add(autoResizeSubsequent);
    autoResizeMenu.add(autoResizeOff);
    autoResizeMenu.add(autoResizeNext);
    autoResizeMenu.add(autoResizeLast);
    autoResizeMenu.add(autoResizeAll);
    JMenu removeMenu = new JMenu("Remove log events");
    removeMenu.setFont(menuLabelFont);
    removeMenu.setIcon(Icons.BIN);
    JLabel removeLabel = new JLabel("Remove by:");
    removeLabel.setFont(menuLabelFont);
    removeMenu.add(removeLabel);

    Map<String, Set<String>> propKeyValue = getPropertiesOfSelectedLogEvents();
    for (AcceptCondition acceptCondition : acceptConditionList) {
        removeMenu.add(new JMenuItem(new RemoveByAcceptanceCriteria(acceptCondition, otrosApplication)));
    }
    for (String propertyKey : propKeyValue.keySet()) {
        for (String propertyValue : propKeyValue.get(propertyKey)) {
            PropertyAcceptCondition propAcceptCondition = new PropertyAcceptCondition(propertyKey,
                    propertyValue);
            removeMenu
                    .add(new JMenuItem(new RemoveByAcceptanceCriteria(propAcceptCondition, otrosApplication)));
        }
    }

    menu.add(new JSeparator());
    JLabel labelMarkingRows = new JLabel("Marking/unmarking rows");
    labelMarkingRows.setFont(menuLabelFont);
    menu.add(labelMarkingRows);
    menu.add(new JSeparator());
    menu.add(mark);
    menu.add(unmark);
    JMenu[] markersMenu = getAutomaticMarkersMenu();
    menu.add(markersMenu[0]);
    menu.add(markersMenu[1]);
    menu.add(new ClearMarkingsAction(otrosApplication));
    menu.add(new JSeparator());
    JLabel labelQuickFilters = new JLabel("Quick filters");
    labelQuickFilters.setFont(menuLabelFont);
    menu.add(labelQuickFilters);
    menu.add(new JSeparator());
    menu.add(focusOnThisThreadAction);
    menu.add(focusOnEventsAfter);
    menu.add(focusOnEventsBefore);
    menu.add(focusOnSelectedClassesAction);
    menu.add(ignoreSelectedEventsClasses);
    menu.add(focusOnSelectedLoggerNameAction);
    menu.add(showCallHierarchyAction);
    for (String propertyKey : propKeyValue.keySet()) {
        for (String propertyValue : propKeyValue.get(propertyKey)) {
            menu.add(new FocusOnSelectedPropertyAction(propertyFilter, propertyFilterPanel.getEnableCheckBox(),
                    otrosApplication, propertyKey, propertyValue));
        }
    }
    menu.add(new JSeparator());
    menu.add(removeMenu);
    menu.add(new JSeparator());
    JLabel labelTableOptions = new JLabel("Table options");
    labelTableOptions.setFont(menuLabelFont);
    menu.add(labelTableOptions);
    menu.add(new JSeparator());
    menu.add(autoResizeMenu);

    menu.add(new JSeparator());
    List<MenuActionProvider> menuActionProviders = otrosApplication.getLogViewPanelMenuActionProvider();
    for (MenuActionProvider menuActionProvider : menuActionProviders) {
        try {
            List<OtrosAction> actions = menuActionProvider.getActions(otrosApplication, this);
            if (actions == null) {
                continue;
            }
            for (OtrosAction action : actions) {
                menu.add(action);
            }
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Cant get action from from provider " + menuActionProvider, e);
        }
    }

    return menu;
}