Re: Horizontally scrolling JTable



Andrew Thompson wrote:
On Mar 28, 7:17 pm, RedGrittyBrick <redgrittybr...@xxxxxxxxxxxxx>
wrote:

I am unable to make my JTable/JScrollPane so that it gains horizontal
crollbars when container width < JTable min width.

Any suggestions?

SSCCE
-----------------------------------8<---------------------------------
import java.awt.BorderLayout;

...

public class HorizScrollTable extends JPanel {

HorizScrollTable() {


column.setPreferredWidth(width);
column.setMinWidth(width); // [2]
}


JPanel p = new JPanel(new BorderLayout());
p.add(table, BorderLayout.CENTER); // [3]
// new ..
p.setPreferredSize( table.getPreferredSize() );
JScrollPane scrollPane = new JScrollPane( p );
....

Thanks, that is perfect in all but one respect ...
Unfortunately the table headings no longer show.

In case I've misread your message, here is my revised constructor:

HorizScrollTable() {
setLayout(new BorderLayout());
JTable table = new JTable(data, headings); // headings!

for (int i = 0; i < headings.length; i++) {
TableColumn column = table.getColumnModel().getColumn(i);
int width = widths[i];
column.setPreferredWidth(width);
column.setMinWidth(width);
}

JPanel p = new JPanel(new BorderLayout());
p.add(table, BorderLayout.CENTER);
p.setPreferredSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane(p);

add(scrollPane, BorderLayout.CENTER);
}

(new readers please see first posting in thread for original SSCCE in full)

Is it impossible to have horizontal scrolling AND headings?
.



Relevant Pages

  • Re: Horizontally scrolling JTable
    ... crollbars when container width < JTable min width. ... JScrollPane scrollPane = new JScrollPane; ... Is it impossible to have horizontal scrolling AND headings? ...
    (comp.lang.java.gui)
  • Re: Horizontally scrolling JTable
    ... scrollbars when container width < JTable min width. ... JPanel p = new JPanel); ... JScrollPane scrollPane = new JScrollPane; ...
    (comp.lang.java.gui)
  • Re: Mouse event type problem
    ... work out where the pointer is in relation to the objects on the JPanel ... when you put components in a Container the container's job it to look ... at at mouse event and figure out which component it belongs to. ...
    (comp.lang.java.programmer)
  • Re: JPanel will not show ( and no more top posting either)
    ... // JFrame addPrinterFrame, deletePrinterFrame, changePrinterFrame; ... JPanel buttonPanel, scrollPanePanel; ... How do I make my panel appear? ... then showing the container. ...
    (comp.lang.java.gui)
  • Re: JPanel will not show ( and no more top posting either)
    ... // JFrame addPrinterFrame, deletePrinterFrame, changePrinterFrame; ... JPanel buttonPanel, scrollPanePanel; ... How do I make my panel appear? ... then showing the container. ...
    (comp.lang.java.gui)