Example usage for javax.swing JTable AUTO_RESIZE_OFF

List of usage examples for javax.swing JTable AUTO_RESIZE_OFF

Introduction

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

Prototype

int AUTO_RESIZE_OFF

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

Click Source Link

Document

Do not adjust column widths automatically; use a horizontal scrollbar instead.

Usage

From source file:org.encog.workbench.dialogs.validate.ResultValidationChart.java

private void drawTable(Vector<Vector<String>> tableData, Vector<String> tableHeaders) {
    JTable table = new JTable(tableData, tableHeaders) {
        private static final long serialVersionUID = 8364655578079933961L;

        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }/*from   w  w w.ja v a  2s .  c o m*/
    };
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    tabs.addTab("Data", new JScrollPane(table));
}

From source file:canreg.client.gui.analysis.FrequenciesByYearInternalFrame.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor./* www .  j  av  a 2  s.com*/
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    rangeFilterPanel = new canreg.client.gui.components.RangeFilterPanel();
    variablesChooserPanel = new canreg.client.gui.components.VariablesChooserPanel();
    printTableButton = new javax.swing.JButton();
    resultPanel = new javax.swing.JPanel();
    resultScrollPane = new javax.swing.JScrollPane();
    resultTable = new javax.swing.JTable();
    popOutTableButton = new javax.swing.JButton();
    saveTableButton = new javax.swing.JButton();

    setClosable(true);
    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    setIconifiable(true);
    setMaximizable(true);
    setResizable(true);
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application
            .getInstance(canreg.client.CanRegClientApp.class).getContext()
            .getResourceMap(FrequenciesByYearInternalFrame.class);
    setTitle(resourceMap.getString("Form.title")); // NOI18N
    setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
    setName("Form"); // NOI18N

    rangeFilterPanel.setName("rangeFilterPanel"); // NOI18N

    variablesChooserPanel.setName("variablesChooserPanel"); // NOI18N

    javax.swing.ActionMap actionMap = org.jdesktop.application.Application
            .getInstance(canreg.client.CanRegClientApp.class).getContext()
            .getActionMap(FrequenciesByYearInternalFrame.class, this);
    printTableButton.setAction(actionMap.get("printTableAction")); // NOI18N
    printTableButton.setName("printTableButton"); // NOI18N

    resultPanel.setName("resultPanel"); // NOI18N

    resultScrollPane.setName("resultScrollPane"); // NOI18N

    resultTable.setAutoCreateRowSorter(true);
    resultTable
            .setModel(new javax.swing.table.DefaultTableModel(new Object[][] { {}, {}, {}, {} }, new String[] {

    }));
    resultTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    resultTable.setName("resultTable"); // NOI18N
    resultScrollPane.setViewportView(resultTable);

    javax.swing.GroupLayout resultPanelLayout = new javax.swing.GroupLayout(resultPanel);
    resultPanel.setLayout(resultPanelLayout);
    resultPanelLayout
            .setHorizontalGroup(resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(resultScrollPane, javax.swing.GroupLayout.Alignment.TRAILING,
                            javax.swing.GroupLayout.DEFAULT_SIZE, 732, Short.MAX_VALUE));
    resultPanelLayout
            .setVerticalGroup(resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(resultScrollPane, javax.swing.GroupLayout.Alignment.TRAILING,
                            javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE));

    popOutTableButton.setAction(actionMap.get("popOutTableAction")); // NOI18N
    popOutTableButton.setName("popOutTableButton"); // NOI18N

    saveTableButton.setAction(actionMap.get("saveTableAction")); // NOI18N
    saveTableButton.setToolTipText(resourceMap.getString("saveTableButton.toolTipText")); // NOI18N
    saveTableButton.setName("saveTableButton"); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                    .addComponent(rangeFilterPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 407,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(saveTableButton, javax.swing.GroupLayout.PREFERRED_SIZE, 115,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(printTableButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(popOutTableButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(variablesChooserPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 309,
                                    Short.MAX_VALUE))
                    .addContainerGap())
            .addComponent(resultPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addGroup(layout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                            .addComponent(variablesChooserPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 249,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(17, 17, 17)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(printTableButton).addComponent(popOutTableButton)
                                    .addComponent(saveTableButton)))
                    .addComponent(rangeFilterPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 288,
                            javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(resultPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    rangeFilterPanel.initValues();
    rangeFilterPanel.setDeskTopPane(dtp);

    pack();
}

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

BamInternalFrame(BamFileRef ref) {
    super(ref.bamFile.getName(), true, false, true, true);
    this.ref = ref;
    JPanel mainPane = new JPanel(new BorderLayout(5, 5));
    setContentPane(mainPane);//from   www . j  av  a  2 s .c om
    JTabbedPane tabbedPane = new JTabbedPane();
    mainPane.add(tabbedPane, BorderLayout.CENTER);

    JPanel pane = new JPanel(new BorderLayout(5, 5));
    tabbedPane.addTab("BAM", pane);

    this.tableModel = new BamTableModel();
    this.jTable = createTable(tableModel);
    this.jTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    this.jTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JScrollPane scroll1 = new JScrollPane(this.jTable);

    this.infoTableModel = new FlagTableModel();
    JTable tInfo = createTable(this.infoTableModel);

    this.genotypeTableModel = new SAMTagAndValueModel();
    JTable tGen = createTable(this.genotypeTableModel);

    this.groupTableModel = new ReadGroupTableModel();
    JTable tGrp = createTable(this.groupTableModel);

    JPanel splitH = new JPanel(new GridLayout(1, 0, 5, 5));
    splitH.add(new JScrollPane(tInfo));
    splitH.add(new JScrollPane(tGen));
    splitH.add(new JScrollPane(tGrp));

    JSplitPane splitVert = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scroll1, splitH);

    this.jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            int row = jTable.getSelectedRow();
            SAMRecord ctx;
            if (row == -1 || (ctx = tableModel.getElementAt(row)) == null) {
                infoTableModel.setContext(null);
                genotypeTableModel.setContext(null);
                groupTableModel.setContext(null);
            } else {
                infoTableModel.setContext(ctx);
                genotypeTableModel.setContext(ctx);
                groupTableModel.setContext(ctx);
            }

        }
    });

    pane.add(splitVert);

    //header as text
    pane = new JPanel(new BorderLayout(5, 5));
    tabbedPane.addTab("Header", pane);
    JTextArea area = new JTextArea(String.valueOf(ref.header.getTextHeader()));
    area.setCaretPosition(0);
    area.setEditable(false);
    pane.add(new JScrollPane(area), BorderLayout.CENTER);

    //dict
    pane = new JPanel(new BorderLayout(5, 5));
    tabbedPane.addTab("Reference", pane);
    JTable dictTable = createTable(new SAMSequenceDictionaryTableModel(ref.header.getSequenceDictionary()));
    dictTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    pane.add(new JScrollPane(dictTable), BorderLayout.CENTER);

    this.selList = new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            listSelectionChanged();
        }
    };

    this.addInternalFrameListener(new InternalFrameAdapter() {
        @Override
        public void internalFrameActivated(InternalFrameEvent e) {
            jTable.getSelectionModel().addListSelectionListener(selList);
        }

        @Override
        public void internalFrameDeactivated(InternalFrameEvent e) {
            jTable.getSelectionModel().removeListSelectionListener(selList);
        }
    });
}

From source file:edu.ku.brc.specify.plugins.sgr.SGRResultsDisplay.java

/**
 * From http://www.pikopong.com/blog/2008/08/13/auto-resize-jtable-column-width/
 * //from w  w w.  j a va  2 s  .c om
 * @param table
 * @param model
 * @return
 */
private JTable autoResizeColWidth(JTable table, DefaultTableModel model) {
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setModel(model);

    int margin = 5;

    for (int i = 0; i < table.getColumnCount(); i++) {
        int vColIndex = i;
        DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
        TableColumn col = colModel.getColumn(vColIndex);
        int width = 0;

        // Get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();

        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
        }

        Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0,
                0);

        width = comp.getPreferredSize().width;

        // Get maximum width of column data
        for (int r = 0; r < table.getRowCount(); r++) {
            renderer = table.getCellRenderer(r, vColIndex);
            comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false,
                    r, vColIndex);
            width = Math.max(width, comp.getPreferredSize().width);
        }

        // Add margin
        width += 2 * margin;

        // Set the width
        col.setPreferredWidth(width);
    }

    ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer())
            .setHorizontalAlignment(SwingConstants.LEFT);

    // table.setAutoCreateRowSorter(true);
    //table.getTableHeader().setReorderingAllowed(false);

    return table;
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * /*from   w  w w .  j a  v  a 2s.c  om*/
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java

/**
 * Class Constructor./*w w  w  . j a va  2  s  .  co m*/
 *
 * @param model
 *
 * @see
 */
public RegistryObjectsTable(TableModel model) {
    // Gives a TableColumnModel so that AutoCreateColumnsFromModel will be false.
    super(model, new DefaultTableColumnModel());

    this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    if (model instanceof RegistryObjectsTableModel) {
        tableModel = (RegistryObjectsTableModel) model;
    } else if (model instanceof TableSorter) {
        tableModel = (RegistryObjectsTableModel) (((TableSorter) model).getModel());
    } else {
        Object[] unexpectedTableModelArgs = { model };
        MessageFormat form = new MessageFormat(resourceBundle.getString("error.unexpectedTableModel"));
        throw new IllegalArgumentException(form.format(unexpectedTableModelArgs));
    }

    setToolTipText(resourceBundle.getString("tip.registryObjectsTable"));

    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    ListSelectionModel rowSM = getSelectionModel();
    stdRowHeight = getRowHeight();
    setRowHeight(stdRowHeight * 3);

    rowSM.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            ListSelectionModel lsm = (ListSelectionModel) e.getSource();

            if (!lsm.isSelectionEmpty()) {
                setSelectedRow(lsm.getMinSelectionIndex());
            } else {
                setSelectedRow(-1);
            }
        }
    });

    createPopup();

    addRenderers();

    // Add listener to self so that I can bring up popup menus on right mouse click
    popupListener = new PopupListener();
    addMouseListener(popupListener);

    //add listener for 'authenticated' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this);

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

private void configureJTable() {
    LookAndFeelManager.setLookAndFeel(jTable);
    //by default allow single line selection
    if (isScrollable || fixedWidth) {
        jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    }/*from w  w  w.  j a va2  s  .  c  o  m*/
    if (createAutoSortCols) {
        jTable.setAutoCreateRowSorter(true);
    }
    jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JTableMouseProcessor jTableMouseProcessor = new JTableMouseProcessor(presenter, this, gridIndex);
    jTable.addMouseListener(getJTableMouseListener(jTableMouseProcessor));
    JTableHeader header = jTable.getTableHeader();
    header.addMouseListener(getJTableHeaderMouseListener(jTableMouseProcessor));
    header.setReorderingAllowed(false);
    jTable.setName("grid" + gridIndex);
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.SimilarCasesFrame.java

private JXTable buidJXTable(final Instances cases) {
    final InstanceTableModel outputCasesTableModel = new InstanceTableModel();
    outputCasesTableModel.setDataset(cases);
    final JXTable outputCasesTable = new JXTable(outputCasesTableModel);
    outputCasesTable.setEditable(false);
    outputCasesTable.setShowHorizontalLines(false);
    outputCasesTable.setShowVerticalLines(false);
    outputCasesTable.setVisibleRowCount(Math.min(10, cases.numInstances())); // FIXME: hardcoded trick
    outputCasesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    final HighlightPredicate myPredicate = new HighlightPredicate() {
        @Override//from www . j  a va 2s .  c o  m
        public boolean isHighlighted(final Component arg0, final ComponentAdapter arg1) {
            final String trueColumnName = (arg1.column > 0) ? cases.attribute(arg1.column - 1).name() : "id";
            final java.util.List<String> inputFieldsList = Arrays.asList(GapFillingKnowledgeDB.INPUT_FIELDS);
            return (inputFieldsList.contains(trueColumnName));
        }
    };
    outputCasesTable.addHighlighter(new ColorHighlighter(myPredicate, null, Color.BLUE));
    outputCasesTable.packAll();
    return outputCasesTable;
}

From source file:net.sourceforge.happybank.main.BankMain.java

private void initComponents() {
    frame = new javax.swing.JFrame();
    menuBar = new javax.swing.JMenuBar();
    menuFile = new javax.swing.JMenu();
    menuItemExit = new javax.swing.JMenuItem();
    menuActions = new javax.swing.JMenu();
    menuItemView = new javax.swing.JMenuItem();
    separator2 = new javax.swing.JSeparator();
    menuHelp = new javax.swing.JMenu();
    separator4 = new javax.swing.JSeparator();
    menuItemAbout = new javax.swing.JMenuItem();
    accountEntries = new javax.swing.JTable();
    accountModel = new AccountTableModel();

    /*// www  . ja  va2  s .  c  o m
     * File menu
     */
    menuFile.setMnemonic('F');
    menuFile.setText("File");
    // - Exit option
    menuItemExit.setMnemonic('X');
    menuItemExit.setText("Exit");
    menuItemExit.setActionCommand("Exit");
    menuItemExit.addActionListener(new ActionHandler());
    menuFile.add(menuItemExit);
    menuBar.add(menuFile);

    // Actions menu
    menuActions.setMnemonic('A');
    menuActions.setText("Actions");
    // - View option
    menuItemView.setMnemonic('V');
    menuItemView
            .setAccelerator(KeyStroke.getKeyStroke('V', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menuItemView.setText("View");
    menuItemView.setActionCommand("View");
    menuItemView.addActionListener(new ActionHandler());
    menuActions.add(menuItemView);
    menuActions.add(separator2);

    // Help menu
    menuHelp.setMnemonic('H');
    menuHelp.setText("Help");
    // - About option
    menuHelp.add(separator4);
    menuItemAbout.setMnemonic('A');
    menuItemAbout.setText("About");
    menuItemAbout.setActionCommand("About");
    menuItemAbout.addActionListener(new ActionHandler());
    menuHelp.add(menuItemAbout);
    menuBar.add(menuHelp);

    /*
     * configure the TabListCellRenderer
     */
    accountEntries.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    accountEntries.setAutoCreateColumnsFromModel(false);
    accountEntries.setModel(accountModel);
    accountEntries.getTableHeader().setReorderingAllowed(false);
    accountEntries.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    accountEntries.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            // capture single click
            if (evt.getClickCount() == 1 && SwingUtilities.isLeftMouseButton(evt)) {
                // ignore
            }
            // capture double click
            if (evt.getClickCount() == 2) {
                // edit the account
                int row = accountEntries.rowAtPoint(evt.getPoint());
                accountEntries.setRowSelectionInterval(row, row);
                onViewAccount();
            }
        } // mouseClicked
    }); // MouseAdapter

    // set the column widths and alignment
    for (int k = 0; k < AccountTableModel.COLUMNS.length; k++) {
        TableCellEditor zipper = new DefaultCellEditor(new JTextField());
        DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer();
        textRenderer.setHorizontalAlignment(AccountTableModel.COLUMNS[k].cAlignment);
        TableColumn column = new TableColumn(k, AccountTableModel.COLUMNS[k].cWidth, textRenderer, zipper);
        accountEntries.addColumn(column);
    }

    // set the table header
    JTableHeader header = accountEntries.getTableHeader();
    header.setUpdateTableInRealTime(false);

    /*
     * create the selection area
     */
    accountPanel = new JPanel();
    accountPanel.setLayout(new BorderLayout());
    scrollPane = new JScrollPane(accountEntries);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new java.awt.Dimension(750, 300));
    accountPanel.add(scrollPane);
    frame.getContentPane().add(accountPanel, java.awt.BorderLayout.CENTER);

    /*
     * layout the frame
     */
    frame.setJMenuBar(menuBar);
    frame.setTitle(APP_NAME);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(screenSize.width / 2 - 300, screenSize.height / 2 - 200);
    // add a listener for the close event
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            onExit();
        }
    });

    loadAccounts();
}

From source file:com.frostwire.gui.bittorrent.PartialFilesDialog.java

private void setupTable() {
    GridBagConstraints c;/*w w  w  . j a  va 2 s.c o m*/
    _table = new JTable() {
        private static final long serialVersionUID = -4266029708016964901L;

        public void paint(java.awt.Graphics g) {
            super.paint(g);

            try {
                if (tablePainted) {
                    return;
                }
                tablePainted = true;

                GUIUtils.adjustColumnWidth(_model, 2, 620, 10, this);
                GUIUtils.adjustColumnWidth(_model, 3, 150, 10, this);
            } catch (Exception e) {
                tablePainted = false;
            }

        };
    };

    _table.setPreferredScrollableViewportSize(new Dimension(600, 300));
    _table.setRowSelectionAllowed(false);
    _table.setModel(_model);
    _table.getColumnModel().getColumn(0).setHeaderValue(""); //checkbox
    _table.getColumnModel().getColumn(1).setHeaderValue(""); //icon
    _table.getColumnModel().getColumn(2).setHeaderValue(I18n.tr("File"));
    _table.getColumnModel().getColumn(3).setHeaderValue(I18n.tr("Type"));
    _table.getColumnModel().getColumn(4).setHeaderValue(I18n.tr("Extension"));
    _table.getColumnModel().getColumn(5).setHeaderValue(I18n.tr("Size"));

    _table.getColumnModel().getColumn(0).setPreferredWidth(30);//checkbox
    _table.getColumnModel().getColumn(1).setPreferredWidth(30);//icon
    _table.getColumnModel().getColumn(2).setPreferredWidth(620);
    _table.getColumnModel().getColumn(3).setPreferredWidth(150);
    _table.getColumnModel().getColumn(4).setPreferredWidth(60);
    _table.getColumnModel().getColumn(5).setPreferredWidth(60);

    _scrollPane = new JScrollPane(_table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    _table.setFillsViewportHeight(true);
    _table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    c = new GridBagConstraints();
    c.insets = new Insets(5, 5, 5, 5);
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 2;
    c.gridheight = 1;
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    panel.add(_scrollPane, c);
}