JTable & JScrollPane

JTable displays with a space on the right in a JScrollPane?

how to get this solved...

thanks

[111 byte] By [b.m.krajua] at [2007-11-27 11:04:10]
# 1

Show us a contained (small) example of code that duplicates the problem you're seeing, and please remember to use the code tags.

PS.

puckstopper31a at 2007-7-29 12:56:14 > top of Java-index,Desktop,Core GUI APIs...
# 2

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.

JayDSa at 2007-7-29 12:56:14 > top of Java-index,Desktop,Core GUI APIs...
# 3

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

b.m.krajua at 2007-7-29 12:56:15 > top of Java-index,Desktop,Core GUI APIs...
# 4

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.

puckstopper31a at 2007-7-29 12:56:15 > top of Java-index,Desktop,Core GUI APIs...
# 5

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.

viravana at 2007-7-29 12:56:15 > top of Java-index,Desktop,Core GUI APIs...
# 6

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(...);

camickra at 2007-7-29 12:56:15 > top of Java-index,Desktop,Core GUI APIs...
# 7

> 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.

puckstopper31a at 2007-7-29 12:56:15 > top of Java-index,Desktop,Core GUI APIs...