List of usage examples for javax.swing JScrollPane getViewport
public JViewport getViewport()
JViewport
. From source file:savant.plugin.builtin.SavantFileRepositoryBrowser.java
public final Component getCenterPanel(List<TreeBrowserEntry> roots) { table = new TreeTable(new TreeBrowserModel(roots) { @Override/* www . j av a 2s . co m*/ public String[] getColumnNames() { return new String[] { "Name", "Description" }; } }); table.setSortable(true); table.setRespectRenderPreferredHeight(true); // configure the TreeTable table.setExpandAllAllowed(true); table.setShowTreeLines(false); table.setSortingEnabled(false); table.setRowHeight(18); table.setShowGrid(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.expandFirstLevel(); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { actOnSelectedItem(true); } } }); // do not select row when expanding a row. table.setSelectRowWhenToggling(false); table.getColumnModel().getColumn(0).setPreferredWidth(200); //table.getColumnModel().getColumn(1).setPreferredWidth(400); //table.getColumnModel().getColumn(2).setPreferredWidth(100); //table.getColumnModel().getColumn(3).setPreferredWidth(100); //table.getColumnModel().getColumn(4).setPreferredWidth(50); table.getColumnModel().getColumn(0).setCellRenderer(FILE_RENDERER); // add searchable feature TableSearchable searchable = new TableSearchable(table) { @Override protected String convertElementToString(Object item) { if (item instanceof TreeBrowserEntry) { return ((TreeBrowserEntry) item).getType(); } return super.convertElementToString(item); } }; searchable.setMainIndex(0); // only search for name column JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setBackground(Color.WHITE); JPanel panel = new JPanel(new BorderLayout(6, 6)); panel.add(scrollPane, BorderLayout.CENTER); panel.setPreferredSize(new Dimension(800, 500)); return panel; }
From source file:savant.thousandgenomes.FTPBrowser.java
public FTPBrowser(URL rootURL) throws IOException { setRoot(rootURL);/*from www . j a va 2 s. c o m*/ setLayout(new BorderLayout()); addressField = new JTextField(); addressField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { setRoot(new URL(addressField.getText())); updateDirectory(); } catch (Exception x) { DialogUtils.displayException("1000 Genomes Plugin", "Unable to change root directory", x); } } }); add(addressField, BorderLayout.NORTH); table = new JTable(); updateDirectory(); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { int row = table.rowAtPoint(evt.getPoint()); try { FTPFile f = ((FTPTableModel) table.getModel()).getEntry(row); if (f == null) { // Going up a directory. curDir = curDir.getParentFile(); updateDirectory(); } else if (f.isDirectory()) { curDir = new File(curDir, f.getName()); updateDirectory(); } else { TrackUtils.createTrack(new URI( "ftp://" + host + new File(curDir, f.getName()).getPath().replace("\\", "/"))); } } catch (Throwable x) { DialogUtils.displayException("FTP Error", "Unable to process FTP request.", x); } } } }); JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setBackground(Color.WHITE); scrollPane.setPreferredSize(new Dimension(800, 500)); add(scrollPane, BorderLayout.CENTER); this.setPreferredSize(new Dimension(800, 500)); }
From source file:savant.view.swing.Frame.java
/** * Construct a new Frame for holding a track. * * @param df the DataFormat, so the frame can do any format-specific * initialisation (e.g. smaller height for sequence tracks) */// w w w.j a va2 s.co m public Frame(DataFormat df) { super(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.TRACK)); sequence = df == DataFormat.SEQUENCE; // Component which displays the legend component. legend = new JComponent() { @Override public Dimension getPreferredSize() { for (Track t : tracks) { Dimension d = t.getRenderer().getLegendSize(t.getDrawingMode()); if (d != null) { return d; } } return new Dimension(0, 0); } @Override public Dimension getMinimumSize() { return getPreferredSize(); } @Override public void paintComponent(Graphics g) { for (Track t : tracks) { Dimension d = t.getRenderer().getLegendSize(t.getDrawingMode()); if (d != null) { Graphics2D g2 = (Graphics2D) g; GradientPaint gp = new GradientPaint(0, 0, Color.WHITE, 0, 60, new Color(230, 230, 230)); g2.setPaint(gp); g2.fillRect(0, 0, d.width, d.height); g2.setColor(Color.BLACK); g2.draw(new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); t.getRenderer().drawLegend(g2, t.getDrawingMode()); return; } } } }; legend.setVisible(false); frameLandscape = new JLayeredPane(); //add graphPane -> jlp -> scrollPane jlp = new JLayeredPane(); jlp.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.gridx = 0; gbc.gridy = 0; //scrollpane JScrollPane scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setWheelScrollingEnabled(false); scrollPane.setBorder(null); graphPane = new GraphPane(this); jlp.add(graphPane, gbc, 0); scrollPane.getViewport().add(jlp); //GRID FRAMEWORK AND COMPONENT ADDING... frameLandscape.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; //add sidepanel sidePanel = new JPanel() { @Override public Dimension getMinimumSize() { return new Dimension(0, 0); } }; sidePanel.setLayout(new GridBagLayout()); sidePanel.setOpaque(false); sidePanel.setVisible(false); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; c.gridx = 1; c.gridy = 0; c.insets = new Insets(0, 0, 0, 16); // Leave 16 pixels so that we don't sit on top of the scroll-bar. frameLandscape.setLayer(sidePanel, JLayeredPane.PALETTE_LAYER); frameLandscape.add(sidePanel, c); addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { Dimension dim = getSize(); if (dim != null) { // TODO: The following shouldn't be necessary, but it seems to be. int expectedWidth = frameLandscape.getWidth(); if (expectedWidth != graphPane.getWidth()) { Dimension goodSize = new Dimension(expectedWidth, graphPane.getHeight()); graphPane.setPreferredSize(goodSize); graphPane.setSize(goodSize); } setLegendVisible(true); } } }); //add graphPane to all cells c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 1.0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.gridheight = 1; c.insets = new Insets(0, 0, 0, 0); frameLandscape.setLayer(scrollPane, JLayeredPane.DEFAULT_LAYER); frameLandscape.add(scrollPane, c); // Add our progress-panel. If setTracks is called promptly, it will be cleared // away before it ever has a chance to draw. getContentPane().add(new ProgressPanel(null), BorderLayout.CENTER); }
From source file:se.llbit.chunky.renderer.ui.RenderControls.java
private void buildUI() { setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); setModalityType(ModalityType.MODELESS); if (!ShutdownAlert.canShutdown()) { // disable the computer shutdown checkbox if we can't shutdown shutdownWhenDoneCB.setEnabled(false); }/* w w w . j av a2s .c om*/ addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { sceneMan.interrupt(); RenderControls.this.dispose(); } @Override public void windowClosed(WindowEvent e) { // halt rendering renderMan.interrupt(); // dispose of the 3D view view.setVisible(false); view.dispose(); } @Override public void windowActivated(WindowEvent e) { } }); updateTitle(); addTab("General", Icon.wrench, buildGeneralPane()); addTab("Lighting", Icon.light, buildLightingPane()); addTab("Sky", Icon.sky, buildSkyPane()); addTab("Water", Icon.water, buildWaterPane()); addTab("Camera", Icon.camera, buildCameraPane()); addTab("Post-processing", Icon.gear, buildPostProcessingPane()); addTab("Advanced", Icon.advanced, buildAdvancedPane()); addTab("Help", Icon.question, buildHelpPane()); JLabel sppTargetLbl = new JLabel("SPP Target: "); sppTargetLbl.setToolTipText("The render will be paused at this SPP count"); JButton setDefaultBtn = new JButton("Make Default"); setDefaultBtn.setToolTipText("Make the current SPP target the default"); setDefaultBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PersistentSettings.setSppTargetDefault(renderMan.scene().getTargetSPP()); } }); targetSPP.update(); JLabel renderLbl = new JLabel("Render: "); setViewVisible(false); showPreviewBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (view.isViewVisible()) { view.hideView(); } else { showPreviewWindow(); } } }); startRenderBtn.setText("START"); startRenderBtn.setIcon(Icon.play.imageIcon()); startRenderBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { switch (renderMan.scene().getRenderState()) { case PAUSED: renderMan.scene().resumeRender(); break; case PREVIEW: renderMan.scene().startRender(); break; case RENDERING: renderMan.scene().pauseRender(); break; } stopRenderBtn.setEnabled(true); } }); stopRenderBtn.setText("RESET"); stopRenderBtn.setIcon(Icon.stop.imageIcon()); stopRenderBtn.setToolTipText("<html>Warning: this will discard the " + "current rendered image!<br>Make sure to save your image " + "before stopping the renderer!"); stopRenderBtn.setEnabled(false); stopRenderBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renderMan.scene().haltRender(); } }); saveFrameBtn.setText("Save Current Frame"); saveFrameBtn.addActionListener(saveFrameListener); sppLbl.setToolTipText("SPP = Samples Per Pixel, SPS = Samples Per Second"); setRenderTime(0); setSamplesPerSecond(0); setSPP(0); setProgress("Progress:", 0, 0, 1); progressLbl.setText("Progress:"); etaLbl.setText("ETA:"); sceneNameLbl.setText("Scene name: "); sceneNameField.setColumns(15); AbstractDocument document = (AbstractDocument) sceneNameField.getDocument(); document.setDocumentFilter(new SceneNameFilter()); document.addDocumentListener(sceneNameListener); sceneNameField.addActionListener(sceneNameActionListener); updateSceneNameField(); saveSceneBtn.setText("Save"); saveSceneBtn.setIcon(Icon.disk.imageIcon()); saveSceneBtn.addActionListener(saveSceneListener); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup() .addGroup(layout.createSequentialGroup().addComponent(sceneNameLbl).addComponent(sceneNameField) .addPreferredGap(ComponentPlacement.RELATED).addComponent(saveSceneBtn)) .addComponent(tabbedPane) .addGroup(layout.createSequentialGroup().addGroup(targetSPP.horizontalGroup(layout)) .addPreferredGap(ComponentPlacement.RELATED).addComponent(setDefaultBtn)) .addGroup(layout.createSequentialGroup().addComponent(renderLbl) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(startRenderBtn) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(stopRenderBtn)) .addGroup( layout.createSequentialGroup().addComponent(saveFrameBtn) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(showPreviewBtn)) .addGroup( layout.createSequentialGroup().addComponent(renderTimeLbl) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(sppLbl)) .addGroup( layout.createSequentialGroup().addComponent(progressLbl) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(etaLbl)) .addComponent(progressBar)).addContainerGap()); layout.setVerticalGroup( layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(sceneNameLbl) .addComponent(sceneNameField).addComponent(saveSceneBtn)) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(tabbedPane) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addGroup(targetSPP.verticalGroup(layout)).addComponent(setDefaultBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(renderLbl) .addComponent(startRenderBtn).addComponent(stopRenderBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup().addComponent(saveFrameBtn) .addComponent(showPreviewBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup().addComponent(renderTimeLbl).addComponent(sppLbl)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup().addComponent(progressLbl).addComponent(etaLbl)) .addComponent(progressBar).addContainerGap()); final JScrollPane scrollPane = new JScrollPane(panel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); setContentPane(scrollPane); scrollPane.getViewport().addChangeListener(new ChangeListener() { private boolean resized = false; @Override public void stateChanged(ChangeEvent e) { if (!resized && scrollPane.getVerticalScrollBar().isVisible()) { Dimension vsbPrefSize = new JScrollPane().getVerticalScrollBar().getPreferredSize(); Dimension size = getSize(); setSize(size.width + vsbPrefSize.width, size.height); resized = true; } } }); pack(); setLocationRelativeTo(chunky.getFrame()); setVisible(true); }
From source file:sk.stuba.fiit.kvasnicka.topologyvisual.gui.components.TopologyPalette.java
public TopologyPalette() { JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add(taskpaneContainer); setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); }
From source file:tk.tomby.tedit.core.Buffer.java
/** * Creates a new Buffer object.//from ww w . ja v a 2 s . c om */ public Buffer() { super(); setLayout(new BorderLayout()); JPanel internalPanel = new JPanel(); internalPanel.setLayout(new BorderLayout()); editor = new ColourTextArea(); int red = PreferenceManager.getInt("general.editor.background.red", 0); int green = PreferenceManager.getInt("general.editor.background.green", 0); int blue = PreferenceManager.getInt("general.editor.background.blue", 0); editor.setBackground(new Color(red, green, blue)); red = PreferenceManager.getInt("general.editor.foreground.red", 0); green = PreferenceManager.getInt("general.editor.foreground.green", 0); blue = PreferenceManager.getInt("general.editor.foreground.blue", 0); editor.setForeground(new Color(red, green, blue)); red = PreferenceManager.getInt("general.editor.selection.red", 0); green = PreferenceManager.getInt("general.editor.selection.green", 0); blue = PreferenceManager.getInt("general.editor.selection.blue", 0); editor.setSelectionColor(new Color(red, green, blue)); String font = PreferenceManager.getString("general.editor.font", "Monospaced"); int size = PreferenceManager.getInt("general.editor.fontSize", 12); editor.setFont(new Font(font, Font.PLAIN, size)); editor.setEditable(true); editor.setDragEnabled(true); editor.setEditorKit(EditorKitManager.createEditorKit(getExtension(DEFAULT_FILE_NAME))); InputMap map = editor.getInputMap(JComponent.WHEN_FOCUSED); for (InputMap imap = map; imap != null; imap = imap.getParent()) { imap.remove(KeyStroke.getKeyStroke('V', InputEvent.CTRL_MASK, false)); imap.remove(KeyStroke.getKeyStroke('C', InputEvent.CTRL_MASK, false)); imap.remove(KeyStroke.getKeyStroke('X', InputEvent.CTRL_MASK, false)); imap.remove(KeyStroke.getKeyStroke('A', InputEvent.CTRL_MASK, false)); } editor.setInputMap(JComponent.WHEN_FOCUSED, map); editor.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent evt) { MessageManager.sendMessage(new BufferMessage(evt.getSource(), BufferMessage.CARET_EVENT)); } }); internalPanel.add(BorderLayout.CENTER, editor); if (PreferenceManager.getBoolean("general.editor.lineNumbers", false)) { lines = new LineNumbering(); lines.setPreferredSize(new Dimension(50, 0)); lines.setFont(new Font(font, Font.PLAIN, size)); lines.setFocusable(false); lines.setDocument(editor.getDocument()); internalPanel.add(BorderLayout.WEST, lines); } JScrollPane scroll = new JScrollPane(internalPanel); scroll.getVerticalScrollBar().setUnitIncrement(10); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); add(BorderLayout.CENTER, scroll); editor.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { if (evt.isPopupTrigger()) { WorkspaceManager.getPopupMenu().show(evt.getComponent(), evt.getX(), evt.getY()); } } public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { WorkspaceManager.getPopupMenu().show(evt.getComponent(), evt.getX(), evt.getY()); } } }); undo = new UndoManager(); undoableListener = new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); MessageManager.sendMessage(new BufferMessage(evt.getSource(), BufferMessage.UNDOABLE_EDIT_EVENT)); if (!modifiedState) { setModifiedState(true); } } }; editor.getDocument().addUndoableEditListener(undoableListener); MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME, this); fileName = DEFAULT_FILE_NAME; }
From source file:tk.tomby.tedit.plugins.explorer.Explorer.java
/** * Creates a new Explorer object.//from w w w . ja va 2 s. c om */ public Explorer() { super("Explorer"); File rootDir = new File(PreferenceManager.getString("explorer.directory", System.getProperty("user.home"))); JPanel internalPanel = new JPanel(); internalPanel.setLayout(new BorderLayout()); topPanel = new TopPanel(rootDir.getAbsolutePath()); topPanel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JComboBox combo = (JComboBox) evt.getSource(); TaskManager.execute(new ReadDirectoryWorker(combo)); } }); internalPanel.add(BorderLayout.NORTH, topPanel); DefaultMutableTreeNode directoryRoot = new DefaultMutableTreeNode(rootDir); directoryTreeModel = new ShortedTreeModel(directoryRoot, new ToStringComparator()); directoryTree = new JTree(directoryTreeModel); directoryTree.setCellRenderer(new DirectoryCellRenderer()); directoryTree.setRootVisible(true); directoryTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); directoryTree.setEnabled(true); directoryTree.setEditable(false); directoryTree.setShowsRootHandles(true); directoryTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getPath(); TreePath leadPath = evt.getNewLeadSelectionPath(); if ((path != null) && (leadPath != null)) { TaskManager.execute(new RefreshWorker(leadPath, false)); } } }); directoryTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) directoryTree .getLastSelectedPathComponent(); if (!node.isRoot()) { File dir = (File) node.getUserObject(); topPanel.setDirectory(dir.getAbsolutePath()); } } } }); JScrollPane directoryScroll = new JScrollPane(directoryTree); directoryScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); directoryScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); directoryScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); fileListModel = new ShortedListModel(new ToStringComparator()); fileList = new JList(fileListModel); fileList.setDragEnabled(true); fileList.setCellRenderer(new FileCellRenderer()); fileList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { final int index = fileList.locationToIndex(evt.getPoint()); TaskManager.execute(new Runnable() { public void run() { File file = (File) fileListModel.getElementAt(index); if (log.isDebugEnabled()) { log.debug(file); } IBuffer buffer = new BufferFactory().createBuffer(); buffer.open(file); WorkspaceManager.addBuffer(buffer); } }); } } }); JScrollPane filesScroll = new JScrollPane(fileList); filesScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); filesScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); filesScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); splitPane = new StrippedSplitPane(JSplitPane.VERTICAL_SPLIT, directoryScroll, filesScroll); splitPane.setBorder(BorderFactory.createEmptyBorder()); splitPane.setOneTouchExpandable(false); splitPane.setDividerSize(5); splitPane.setDividerLocation(PreferenceManager.getInt("explorer.divider", 0)); List<MutableTreeNode> dirs = openDirectory(rootDir); directoryTreeModel.insertAllInto(dirs, directoryRoot); List<File> files = getFiles(rootDir); fileListModel.addAll(files); directoryTree.expandRow(0); internalPanel.add(splitPane, BorderLayout.CENTER); setContent(internalPanel); }
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); }// w ww. j av a 2s.com 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; }