Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand you correctly, you want the column headers of your table to appear in the column headers of the viewport but you want something else in the viewport view?</p> <p>Then you need to grab the table header and set it as the column header of the viewport.</p> <p>Here is an example:</p> <pre><code>import java.awt.BorderLayout; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class TestTableHeader { protected void initUI() { Vector&lt;Vector&lt;Object&gt;&gt; data = new Vector&lt;Vector&lt;Object&gt;&gt;(); Vector&lt;String&gt; colNames = new Vector&lt;String&gt;(); for (int i = 0; i &lt; 5; i++) { colNames.add("Col-" + (i + 1)); } table = new JTable(data, colNames); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); scrollpane = new JScrollPane(); scrollpane.setColumnHeaderView(table.getTableHeader()); scrollpane.setViewportView(new JLabel("some label in the viewport view")); frame.add(scrollpane, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } private JTable table; private JScrollPane scrollpane; public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new TestTableHeader().initUI(); } }); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload