JScroller on JTable and table size
Hi everyone...
I have a small problem...i added JScrollPane to my JTable...but if i do the following...
JScrollPane contentScroller=new JScrollPane(myJTable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
/* ............ */
myJTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
In this case scroller works great....accept if i have a smaller data set to show...for example only one column...
Basically what i would like is to be able to set like minimum size of my JTable...is that possible...
[636 byte] By [
Samuraya] at [2007-11-26 19:13:28]

# 3
Oh ya...
sorry i apologize...
Well basically what i did is the following...
In the constructor of my sub-class that extends JTable i set the following property:
/*...........................................................................*/
this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
/*...........................................................................*/
And then i also added the following code...(i created some additional methods...i dont really know if this is the right way but i didnt find anything more suitable for my problem)
/*i set JScrollPane onto witch i added my JTable class instance, to a private JscrollPane variable*/
public void setParentJPanel(JScrollPane parentJScrollPane){
this.parentJScrollPane = parentJScrollPane;
}
/*I only added these 3 methods cos i wanted to get the size of JScrollPane onto witch i added my JTable class instance*/
public JScrollPane getParentJPanel(){
return this.parentJScrollPane;
}
/*this methods sort of sets all the columns to equal size witch i guess i wanted it to do...*/
public void setAllColumnsWidth(){
int parentWidth = this.getParentJPanel().getWidth();
int columnNumber = this.getColumnNumber();/*method that i wrote to work with another class that works with database*/
int columnWidth = parentWidth/columnNumber;
for(int i=0;i < columnNumber;i++)
this.getColumnModel().getColumn(i).setPreferredWidth(columnWidth);
}
Hmmm sorry again for not posting my solution...its not really that much impressive thats why i didnt post it the first time...
Well i hope it helps....(what i needed is basically how to set columns to as equal size as possible...)