Pessoal,
Tenho um JTable e coloquei um JScrollBar nele. Um código mais ou menos assim:
JTable jtable = new JTable(data, headers);
JScrollPane scrool = new JScrollPane(jtable);
Eu gostaria que a rolagem vertical e horizontal fosse exibida. Porém só aparece a vertical. Na rolagem horizontal uma parte da tabela não é mostrada quando eu diminuo a janela, mas o scroll horizontal não aparece.
Eu já usei o código:
jtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Esse código funcionou, porém eu preciso que table seja redimensionada. Logo não me ajuda muito.
Eu tentei também usar o código:
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(JScrollPane .HORIZONTAL_SCROLLBAR_ALWAYS);
Ai o scroll aparece mas não funciona a rolagem.
Alguem me sugere algo?
Muito obrigado.
Além do código que voce colocou, tente fazer com que as colunas nao tenham tamanho fixo.
for (int i = 0; i < table.getColumnCount(); i++){
table.getColumnModel().getColumn(i).setResizable(true);
}
abraços,
gqueiroz
Olá muito obrigado pela respota 
Eu tentei colocar o código que vc sugeriu mas mesmo assim ainda persiste o problema, pois se eu tiro o código:
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
O codigo que vc sugeriu reduz o tamanho das células e faz com que a rolagem não apareça.
Agora se eu deixo o código acima, ai o código:
for (int i = 0; i < table.getColumnCount(); i++){
table.getColumnModel().getColumn(i).setResizable(true);
}
Não surte efeito 
Vixi e agora? heheh 
qual o gerenciador de layout que voce está utilizando?
Vixi eu to fazendo assim direto o:
frame.getContentPane().add(scroll);
Bom, de qualquer forma seria interessante voce mostrar o codigo pra ver o que pode ser feito
Aqui vai o código
JFrame frame = new JFrame("Sample Application");
TableModel tm = new EPTableModel();
JTable table = new EPTable(tm);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setAutoscrolls(true);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED);
frame.getContentPane().add(scrollPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);
//table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
for (int i = 0; i < table.getColumnCount(); i++){
table.getColumnModel().getColumn(i).setResizable(true);
table.getColumnModel().getColumn(i).setMinWidth(50);
}
frame.setVisible(true);
Aqui tem uma classe de exemplo que usei, bem simples. Acho que se funcionar nela no meu prog. tb vai:
package demo;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class SimpleTableDemo extends JPanel {
private boolean DEBUG = false;
public SimpleTableDemo() {
super(new GridLayout(1,0));
String[] columnNames = {"Category",
"05/07/2006",
"05/08/2006",
"05/09/2006",
"05/10/2006"};
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
}
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("Event Plot Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
SimpleTableDemo newContentPane = new SimpleTableDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
estranho, executei o codigo abaixo e funcionou, tive que criar um DefaultTableModel, foi a unica diferença.
JFrame frame = new JFrame("Sample Application");
TableModel tm = new DefaultTableModel(new String[]{"Nome","Fone"},5);
JTable table = new JTable(tm);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setAutoscrolls(true);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED);
frame.getContentPane().add(scrollPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
frame.setVisible(true);
Entao, funcionou pq tem a linha:
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Mas eu preciso que as celulas sejam redimensionáveis até um certo tamanho 
Por favor tente executar este código e depois qdo tiver executando redimensione a janela, vc vai ver que nao aparece a rolagem horizontal.
JFrame frame = new JFrame("Sample Application");
TableModel tm = new DefaultTableModel(new String[]{"Nome","Fone"},5);
JTable table = new JTable(tm);
for (int i = 0; i < table.getColumnCount(); i++){
table.getColumnModel().getColumn(i).setMinWidth(100);
}
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setAutoscrolls(true);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED);
frame.getContentPane().add(scrollPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);
frame.setVisible(true);
Cara, eu passei pelo mesmo problema e fiz assim:
JTable table = new JTable(Objecj[][],Object[]);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
e funcionou!!!
Pois é… funciona mesmo, mas o problema é que o tamanho das células fica fixo. Se eu maximizar a tela as células nao aumentam o tamanho 