JTable & JScrollPane
JTable displays with a space on the right in a JScrollPane?
how to get this solved...
thanks
JTable displays with a space on the right in a JScrollPane?
how to get this solved...
thanks
Show us a contained (small) example of code that duplicates the problem you're seeing, and please remember to use the code tags.
PS.
You need to create a Short, Self Contained, Compilable and Executable, Example Program as in
http://homepage1.nifty.com/algafield/sscce.html
that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing
based on the information provided.
And don't forget to use the Code Formatting Tags
http://forum.java.sun.com/help.jspa?sec=formatting
so the code retains its original formatting.
rows=new Vector();
columns= new Vector();
String[] columnNames =
{
"File ID",
"Description"
};
//addColumns(columnNames);
tabModel=new DefaultTableModel();
tabModel.setDataVector(rows,columns);
table = new JTable(tabModel){
public boolean isCellEditable(int rowindex, int vCol){
return false;
}
};
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(20,200,580,235);
scrollPane.setPreferredSize(new Dimension(510,490));
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.add(scrollPane);// adding the scroll pane to panel
I don't see where you are putting the table on the scroll pane which would be
scrollPane.setViewportView(table) ;
There's not really enough here to tell me what's causing your problem. (BTW by itself this won't compile and run so I can't duplicate your problem.)
PS.
your table has two columns -- not enough to fill a scrollpane with a preferred size of 510x490. try to add more columms or remove setBounds/setPReferredSize
;o)
V.V.
I guess you really don't want any help. You still haven't posted a SSCCE.
> I don't see where you are putting the table on the scroll pane
JScrollPane scrollPane = new JScrollPane(table);
Works fine when you create the scroll pane. If you want to add a component to an existing scroll pane you need to use setViewportView(...);
> I guess you really don't want any help. You still
> haven't posted a SSCCE.
>
> > I don't see where you are putting the table on the
> scroll pane
> JScrollPane scrollPane = new
> JScrollPane(table);
Works fine when you create
> the scroll pane. If you want to add a component to an
> existing scroll pane you need to use
> setViewportView(...);
Well duh of course it works my old eyes just skipped right over that line of code. *thumps self in head several times*
PS.