List of usage examples for javax.swing.event TableColumnModelListener TableColumnModelListener
TableColumnModelListener
From source file:MainClass.java
public static void main(String args[]) { Object rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } }; Object headers[] = { "Upper", "Lower" }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); TableColumnModelListener tableColumnModelListener = new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent e) { System.out.println("Added"); }/*from w w w.j a v a2 s . co m*/ public void columnMarginChanged(ChangeEvent e) { System.out.println("Margin"); } public void columnMoved(TableColumnModelEvent e) { System.out.println("Moved"); } public void columnRemoved(TableColumnModelEvent e) { System.out.println("Removed"); } public void columnSelectionChanged(ListSelectionEvent e) { System.out.println("Selection Changed"); } }; TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(tableColumnModelListener); columnModel.setColumnMargin(12); TableColumn column = new TableColumn(1); columnModel.addColumn(column); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:ColumnModelSample.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; final Object headers[] = { "English", "#" }; JFrame frame = new JFrame("Scrollless Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); TableColumnModelListener tableColumnModelListener = new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent e) { System.out.println("Added"); }//from w ww. jav a 2 s . c om public void columnMarginChanged(ChangeEvent e) { System.out.println("Margin"); } public void columnMoved(TableColumnModelEvent e) { System.out.println("Moved"); } public void columnRemoved(TableColumnModelEvent e) { System.out.println("Removed"); } public void columnSelectionChanged(ListSelectionEvent e) { System.out.println("Selection Changed"); } }; TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(tableColumnModelListener); columnModel.setColumnMargin(12); TableColumn column = new TableColumn(1); columnModel.addColumn(column); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" }, { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" }, { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" }, { "ten", "ju - \u5341" } }; Object headers[] = { "English", "Japanese" }; JFrame frame = new JFrame("Scrollless Table"); JTable table = new JTable(rows, headers); TableColumnModelListener tableColumnModelListener = new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent e) { System.out.println("Added"); }// w w w .ja v a 2 s . c o m public void columnMarginChanged(ChangeEvent e) { System.out.println("Margin"); } public void columnMoved(TableColumnModelEvent e) { System.out.println("Moved"); } public void columnRemoved(TableColumnModelEvent e) { System.out.println("Removed"); } public void columnSelectionChanged(ListSelectionEvent e) { System.out.println("Selection Changed"); } }; TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(tableColumnModelListener); columnModel.setColumnMargin(12); TableColumn column = new TableColumn(1); columnModel.addColumn(column); frame.getContentPane().add(table, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:com.qspin.qtaste.ui.reporter.TestCaseReportTable.java
private void init() { final String tableLayoutProperty = interactive ? INTERACTIVE_TABLE_LAYOUT_PROPERTY : EXECUTION_TABLE_LAYOUT_PROPERTY; final String statusColumnProperty = tableLayoutProperty + ".status"; final String testCaseColumnProperty = tableLayoutProperty + ".test_case"; final String detailsColumnProperty = tableLayoutProperty + ".details"; final String testbedColumnProperty = tableLayoutProperty + ".testbed"; final String resultColumnProperty = tableLayoutProperty + ".result"; tcModel = new DefaultTableModel( new Object[] { "Status", "Test Case", "Details", "Result", "Testbed", "Time", "." }, 0) { @Override/*from w ww . j a v a 2 s . co m*/ public Class<?> getColumnClass(int columnIndex) { Class<?> dataType = super.getColumnClass(columnIndex); if (columnIndex == STATUS) { dataType = Icon.class; } return dataType; } @Override public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; tcTable = new SortableJTable(new TableSorter(tcModel)) { public String getToolTipText(MouseEvent e) { Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); if (colIndex < 0) { return null; } return convertObjectToToolTip(getValueAt(rowIndex, colIndex)); } }; tcTable.setColumnSelectionAllowed(false); int tcWidth = interactive ? 360 : 480; int tcStatusWidth = 40; int tcTestbedWidth = 100; int tcDetailsWidth = 360; int tcResultWidth = 150; GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); List<?> list = guiConfiguration.configurationsAt(tableLayoutProperty); if (!list.isEmpty()) { try { tcWidth = guiConfiguration.getInt(testCaseColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(testCaseColumnProperty, tcWidth); } try { tcStatusWidth = guiConfiguration.getInt(statusColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth); } try { tcDetailsWidth = guiConfiguration.getInt(detailsColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth); } try { tcTestbedWidth = guiConfiguration.getInt(testbedColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth); } if (interactive) { try { tcResultWidth = guiConfiguration.getInt(resultColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(resultColumnProperty, tcResultWidth); } } } else { tcWidth = interactive ? 360 : 480; guiConfiguration.setProperty(testCaseColumnProperty, tcWidth); guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth); guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth); guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth); if (interactive) { guiConfiguration.setProperty(resultColumnProperty, tcResultWidth); } try { guiConfiguration.save(); } catch (ConfigurationException ex) { logger.error("Error while saving GUI configuration: " + ex.getMessage()); } } TableColumnModel tcTableColumnModel = tcTable.getColumnModel(); tcTableColumnModel.getColumn(TEST_CASE).setPreferredWidth(tcWidth); tcTableColumnModel.getColumn(STATUS).setPreferredWidth(tcStatusWidth); tcTableColumnModel.getColumn(STATUS).setMaxWidth(40); tcTableColumnModel.getColumn(DETAILS).setPreferredWidth(tcDetailsWidth); tcTableColumnModel.getColumn(TESTBED).setPreferredWidth(tcTestbedWidth); tcTableColumnModel.getColumn(EXEC_TIME).setPreferredWidth(70); tcTableColumnModel.getColumn(EXEC_TIME).setMinWidth(70); tcTableColumnModel.getColumn(EXEC_TIME).setMaxWidth(70); tcTableColumnModel.removeColumn(tcTableColumnModel.getColumn(TC)); if (!interactive) { tcTable.getSelectionModel().addListSelectionListener(new TCResultsSelectionListeners()); } tcTable.setName("tcTable"); tcTableColumnModel.addColumnModelListener(new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent e) { } public void columnRemoved(TableColumnModelEvent e) { } public void columnMoved(TableColumnModelEvent e) { } public void columnMarginChanged(ChangeEvent e) { try { // save the current layout int tcStatusWidth = tcTable.getColumnModel().getColumn(STATUS).getWidth(); int tcWidth = tcTable.getColumnModel().getColumn(TEST_CASE).getWidth(); int tcDetailsWidth = tcTable.getColumnModel().getColumn(DETAILS).getWidth(); int tcResultWidth = tcTable.getColumnModel().getColumn(RESULT).getWidth(); int tcTestbedWidth = tcTable.getColumnModel().getColumn(TESTBED).getWidth(); // save it into the settings GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth); guiConfiguration.setProperty(testCaseColumnProperty, tcWidth); guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth); guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth); if (interactive) { guiConfiguration.setProperty(resultColumnProperty, tcResultWidth); } guiConfiguration.save(); } catch (ConfigurationException ex) { logger.error("Error while saving GUI configuration: " + ex.getMessage()); } } public void columnSelectionChanged(ListSelectionEvent e) { } }); try { tcTable.setDefaultRenderer(Class.forName("java.lang.Object"), new TableCellRenderer()); } catch (ClassNotFoundException ex) { } if (interactive) { displayTableForInteractiveMode(); } else { displayTableForExecutionMode(); } tcTable.addMouseListener(new TableMouseListener()); // use timer for updating elapsed time every seconds timer.schedule(new TimerTask() { @Override public void run() { updateRunningTestCaseElapsedTime(); } }, 1000, 1000); }
From source file:com.diversityarrays.kdxplore.field.FieldViewDialog.java
public FieldViewDialog(Window owner, String title, SampleGroupChoice sgcSamples, Trial trial, SampleGroupChoice sgcNewMedia, KDSmartDatabase db) throws IOException { super(owner, title, ModalityType.MODELESS); advanceRetreatControls = Box.createHorizontalBox(); advanceRetreatControls.add(new JButton(retreatAction)); advanceRetreatControls.add(new JButton(advanceAction)); autoAdvanceControls = Box.createHorizontalBox(); autoAdvanceControls.add(new JButton(autoAdvanceAction)); autoAdvanceOption.addActionListener(new ActionListener() { @Override/*w w w.j a v a2s .c o m*/ public void actionPerformed(ActionEvent e) { updateMovementControls(); } }); this.database = db; this.sampleGroupChoiceForSamples = sgcSamples; this.sampleGroupChoiceForNewMedia = sgcNewMedia; NumberSpinner fontSpinner = new NumberSpinner(new SpinnerNumberModel(), "0.00"); this.fieldViewPanel = FieldViewPanel.create(database, trial, SeparatorVisibilityOption.VISIBLE, null, Box.createHorizontalGlue(), new JButton(showInfoAction), Box.createHorizontalGlue(), new JLabel("Font Size:"), fontSpinner, Box.createHorizontalGlue(), advanceRetreatControls, autoAdvanceOption, autoAdvanceControls); initialiseAction(advanceAction, "ic_object_advance_black.png", "Auto-Advance"); this.xyProvider = fieldViewPanel.getXYprovider(); this.traitMap = fieldViewPanel.getTraitMap(); fieldLayoutTable = fieldViewPanel.getFieldLayoutTable(); JScrollPane scrollPane = fieldViewPanel.getFieldTableScrollPane(); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); fieldLayoutTable.setTransferHandler(flth); fieldLayoutTable.setDropMode(DropMode.ON); fieldLayoutTable.addMouseListener(new MouseAdapter() { JPopupMenu popupMenu; @Override public void mouseClicked(MouseEvent e) { if (!SwingUtilities.isRightMouseButton(e) || 1 != e.getClickCount()) { return; } Point pt = e.getPoint(); int row = fieldLayoutTable.rowAtPoint(pt); if (row >= 0) { int col = fieldLayoutTable.columnAtPoint(pt); if (col >= 0) { Plot plot = fieldViewPanel.getPlotAt(col, row); if (plot != null) { if (popupMenu == null) { popupMenu = new JPopupMenu("View Attachments"); } popupMenu.removeAll(); Set<File> set = plot.getMediaFiles(); if (Check.isEmpty(set)) { popupMenu.add(new JMenuItem("No Attachments available")); } else { for (File file : set) { Action a = new AbstractAction(file.getName()) { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(file.toURI()); } catch (IOException e1) { MsgBox.warn(FieldViewDialog.this, e1, file.getName()); } } }; popupMenu.add(new JMenuItem(a)); } } popupMenu.show(fieldLayoutTable, pt.x, pt.y); } } } } }); Font font = fieldLayoutTable.getFont(); float fontSize = font.getSize2D(); fontSizeModel = new SpinnerNumberModel(fontSize, fontSize, 50.0, 1.0); fontSpinner.setModel(fontSizeModel); fontSizeModel.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { float fsize = fontSizeModel.getNumber().floatValue(); System.out.println("Using fontSize=" + fsize); Font font = fieldLayoutTable.getFont().deriveFont(fsize); fieldLayoutTable.setFont(font); FontMetrics fm = fieldLayoutTable.getFontMetrics(font); int lineHeight = fm.getMaxAscent() + fm.getMaxDescent(); fieldLayoutTable.setRowHeight(4 * lineHeight); // GuiUtil.initialiseTableColumnWidths(fieldLayoutTable, false); fieldLayoutTable.repaint(); } }); fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); fieldLayoutTable.setResizable(true, true); fieldLayoutTable.getTableColumnResizer().setResizeAllColumns(true); advanceAction.setEnabled(false); fieldLayoutTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { handlePlotSelection(); } } }); TableColumnModel columnModel = fieldLayoutTable.getColumnModel(); columnModel.addColumnModelListener(new TableColumnModelListener() { @Override public void columnSelectionChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { handlePlotSelection(); } } @Override public void columnRemoved(TableColumnModelEvent e) { } @Override public void columnMoved(TableColumnModelEvent e) { } @Override public void columnMarginChanged(ChangeEvent e) { } @Override public void columnAdded(TableColumnModelEvent e) { } }); PropertyChangeListener listener = new PropertyChangeListener() { // Use a timer and redisplay other columns when delay is GT 100 ms Timer timer = new Timer(true); TimerTask timerTask; long lastActive; boolean busy = false; private int eventColumnWidth; private TableColumn eventColumn; @Override public void propertyChange(PropertyChangeEvent evt) { if (busy) { return; } if (evt.getSource() instanceof TableColumn && "width".equals(evt.getPropertyName())) { eventColumn = (TableColumn) evt.getSource(); eventColumnWidth = eventColumn.getWidth(); lastActive = System.currentTimeMillis(); if (timerTask == null) { timerTask = new TimerTask() { @Override public void run() { if (System.currentTimeMillis() - lastActive > 200) { timerTask.cancel(); timerTask = null; busy = true; try { for (Enumeration<TableColumn> en = columnModel.getColumns(); en .hasMoreElements();) { TableColumn tc = en.nextElement(); if (tc != eventColumn) { tc.setWidth(eventColumnWidth); } } } finally { busy = false; } } } }; timer.scheduleAtFixedRate(timerTask, 100, 150); } } } }; for (Enumeration<TableColumn> en = columnModel.getColumns(); en.hasMoreElements();) { TableColumn tc = en.nextElement(); tc.addPropertyChangeListener(listener); } Map<Integer, Plot> plotById = new HashMap<>(); for (Plot plot : fieldViewPanel.getFieldLayout()) { plotById.put(plot.getPlotId(), plot); } TrialItemVisitor<Sample> sampleVisitor = new TrialItemVisitor<Sample>() { @Override public void setExpectedItemCount(int count) { } @Override public boolean consumeItem(Sample sample) throws IOException { Plot plot = plotById.get(sample.getPlotId()); if (plot == null) { throw new IOException("Missing plot for plotId=" + sample.getPlotId() + " sampleIdent=" + Util.createUniqueSampleKey(sample)); } plot.addSample(sample); SampleCounts counts = countsByTraitId.get(sample.getTraitId()); if (counts == null) { counts = new SampleCounts(); countsByTraitId.put(sample.getTraitId(), counts); } if (sample.hasBeenScored()) { ++counts.scored; } else { ++counts.unscored; } return true; } }; database.visitSamplesForTrial(sampleGroupChoiceForSamples, trial.getTrialId(), SampleOrder.ALL_BY_PLOT_ID_THEN_TRAIT_ID_THEN_INSTANCE_NUMBER_ORDER_THEN_SPECIMEN_NUMBER, sampleVisitor); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.trial = trial; KDClientUtils.initAction(ImageId.SETTINGS_24, showInfoAction, "Trial Summary"); Action clear = new AbstractAction("Clear") { @Override public void actionPerformed(ActionEvent e) { infoTextArea.setText(""); } }; JPanel bottom = new JPanel(new BorderLayout()); bottom.add(GuiUtil.createLabelSeparator("Plot Details", new JButton(clear)), BorderLayout.NORTH); bottom.add(new JScrollPane(infoTextArea), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, fieldViewPanel, new JScrollPane(infoTextArea)); splitPane.setResizeWeight(0.0); splitPane.setOneTouchExpandable(true); setContentPane(splitPane); updateMovementControls(); pack(); }
From source file:org.nuclos.client.ui.collect.result.ResultController.java
/** * change column ordering in table model when table columns * are reordered by dragging a column with the mouse *//*w ww. ja va 2s . c o m*/ private TableColumnModelListener newColumnModelListener() { return new TableColumnModelListener() { @Override public void columnMoved(TableColumnModelEvent ev) { final int iFromColumn = ev.getFromIndex(); final int iToColumn = ev.getToIndex(); if (iFromColumn != iToColumn) { //log.debug("column moved from " + iFromColumn + " to " + iToColumn); // Sync the "selected fields" with the table column model: getResultPanel().columnMovedInHeader(clctctl.getFields()); // Note that the columns of the result table model are not adjusted here. // That means, the table column model and the table model are not 1:1 - // use JTable.convertColumnIndexToModel to convert between the two. } } @Override public void columnAdded(TableColumnModelEvent ev) { } @Override public void columnRemoved(TableColumnModelEvent ev) { } @Override public void columnMarginChanged(ChangeEvent ev) { } @Override public void columnSelectionChanged(ListSelectionEvent ev) { } }; }
From source file:org.openflexo.technologyadapter.excel.view.ExcelSheetView.java
public ExcelSheetView(ExcelSheet sheet, FlexoController controller) { super(new BorderLayout()); this.sheet = sheet; this.controller = controller; tableModel = new ExcelSheetTableModel(); table = new MultiSpanCellTable(tableModel); table.setBackground(Color.WHITE); table.setShowGrid(true);/*from w ww .ja v a2 s . c om*/ table.setGridColor(Color.LIGHT_GRAY); table.setRowMargin(0); table.getColumnModel().setColumnMargin(0); for (int i = 0; i < tableModel.getColumnCount(); i++) { TableColumn col = table.getColumnModel().getColumn(i); if (i == 0) { col.setWidth(25); col.setPreferredWidth(25); col.setMinWidth(25); col.setMaxWidth(100); // col.setResizable(false); col.setHeaderValue(null); } else { col.setWidth(sheet.getSheet().getColumnWidth(i - 1) / 40); col.setPreferredWidth(sheet.getSheet().getColumnWidth(i - 1) / 40); col.setHeaderValue("" + Character.toChars(i + 64)[0]); } } table.setDefaultRenderer(Object.class, new ExcelSheetCellRenderer()); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); add(new JScrollPane(table), BorderLayout.CENTER); cellIdentifier = new JTextField(6); cellIdentifier.setEditable(false); cellIdentifier.setHorizontalAlignment(SwingConstants.CENTER); cellValue = new JTextField(); cellValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { valueEditedForSelectedCell(cellValue.getText()); } }); /*cellValue.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } @Override public void insertUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } @Override public void changedUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } });*/ JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(cellIdentifier, BorderLayout.WEST); topPanel.add(cellValue, BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { selectionChanged(); } }); table.getColumnModel().addColumnModelListener(new TableColumnModelListener() { @Override public void columnSelectionChanged(ListSelectionEvent e) { selectionChanged(); } @Override public void columnRemoved(TableColumnModelEvent e) { } @Override public void columnMoved(TableColumnModelEvent e) { } @Override public void columnMarginChanged(ChangeEvent e) { } @Override public void columnAdded(TableColumnModelEvent e) { } }); updateRowHeights(); validate(); /*for (Object p : sheet.getSheet().getWorkbook().getAllPictures()) { System.out.println("Picture: " + p); } System.out.println("class = " + sheet.getSheet().getClass()); if (sheet.getSheet() instanceof HSSFSheet) { List<HSSFShape> shapes = ((HSSFSheet) sheet.getSheet()).getDrawingPatriarch().getChildren(); System.out.println("Prout=" + shapes); for (int i = 0; i < shapes.size(); i++) { System.out.println("hop avec " + shapes.get(i)); if (shapes.get(i) instanceof HSSFPicture) { HSSFPicture pic = (HSSFPicture) shapes.get(i); HSSFPictureData picdata = ((HSSFSheet) sheet.getSheet()).getWorkbook().getAllPictures().get(pic.getPictureIndex()); System.out.println("New picture found : " + pic); System.out.println("Anchor : " + pic.getAnchor()); System.out.println("file extension " + picdata.suggestFileExtension()); // int pictureIndex = this.newSheet.getWorkbook().addPicture( picdata.getData(), picdata.getFormat()); // this.newSheet.createDrawingPatriarch().createPicture((HSSFClientAnchor)pic.getAnchor()r, pictureIndex); } } }*/ }
From source file:ua.com.fielden.platform.example.swing.egi.EgiExample.java
private void addTotalsFooterTo(final EntityGridInspector egi, final JPanel topPanel) { // final JPanel panel = new JPanel(new MigLayout("insets 0", "[]", "[]0[]push[]")); // panel.add(egi.getTableHeader(), "grow, wrap"); // panel.add(egi, "grow, wrap"); final JScrollPane scrollPane = new JScrollPane(egi); topPanel.add(scrollPane, "grow, wrap"); final JPanel footer = new JPanel(new MigLayout("nogrid, insets 0")); // footer.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); final List<JComponent> totalsComponents = new ArrayList<JComponent>(); for (int i = 0; i < egi.getColumnCount(); i++) { final TableColumn column = egi.getColumnModel().getColumn(i); final JComponent totalsComponent = i % 2 == 0 ? new JTextField("totals " + i) : new JLabel(); totalsComponent.setPreferredSize(new Dimension(column.getPreferredWidth(), 30)); footer.add(totalsComponent, "grow"); totalsComponents.add(totalsComponent); }//from w w w. jav a 2 s . c o m final JScrollPane footerPane = new JScrollPane(footer, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); topPanel.add(footerPane, "grow, wrap, h 40::"); topPanel.add(scrollPane.getHorizontalScrollBar(), "grow, wrap"); scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(final AdjustmentEvent e) { footerPane.getViewport().setViewPosition(new Point(e.getValue(), 0)); } }); egi.getColumnModel().addColumnModelListener(new TableColumnModelListener() { @Override public void columnAdded(final TableColumnModelEvent e) { } @Override public void columnMarginChanged(final ChangeEvent e) { final TableColumn column = egi.getTableHeader().getResizingColumn(); if (column != null) { final JComponent totalsComponent = totalsComponents .get(egi.convertColumnIndexToView(column.getModelIndex())); totalsComponent.setPreferredSize(new Dimension(column.getWidth(), totalsComponent.getHeight())); footer.revalidate(); } } @Override public void columnMoved(final TableColumnModelEvent e) { final JComponent fromComponent = totalsComponents.get(e.getFromIndex()); totalsComponents.set(e.getFromIndex(), totalsComponents.get(e.getToIndex())); totalsComponents.set(e.getToIndex(), fromComponent); footer.removeAll(); for (int i = 0; i < egi.getColumnCount(); i++) { footer.add(totalsComponents.get(i), "grow, gap 0 0 0 0"); } footer.revalidate(); } @Override public void columnRemoved(final TableColumnModelEvent e) { } @Override public void columnSelectionChanged(final ListSelectionEvent e) { } }); // // return panel; }