JTable + Scroll

0 respostas
K

O Scroll não funciona, nem mesmo aparece no seguinte codigo:

package loop;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;


public class Loop extends JFrame{
    
    DefaultTableModel modelo;
    
    JTextField text;
    
    JButton ir = new JButton ("ir");
    
    JScrollPane jScroll;
    
    public Loop()
    {
     //Propriedades da Janela;
     setResizable(false);
     setBounds(0,0,400,500);
     getContentPane().setLayout(null);
     
     //Definir as Strings de coluna e conteudo;
     String[] colunas = new String[]{"Erro","Descrição"};
     String[][] conteudo = new String[][]{
         {"Erro","Descrição"}
     };
     
     //JTextField
     text = new JTextField();
     text.setLocation(10,10);
     text.setSize(100,20);

     //JButton ir
     ir.setLocation(115,10);
     ir.setSize(100,20);
     
     //Sair quando fechar;
     this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
     
     //Tabela;
     modelo = new DefaultTableModel(conteudo,colunas);
     
     JTable table = new JTable(modelo);
     table.setLocation(1,200);
     table.setSize(398,199);
     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     
     //jScroll
     jScroll = new JScrollPane(table);
     jScroll.setAutoscrolls(true);
     jScroll.getVerticalScrollBar(); 

     
     //Action Performed/////////////////////////////////////////////////////////
         ir.addActionListener( new ActionListener()
         {
             public void actionPerformed( ActionEvent ae )
             {
               String b = text.getText();
               int a = Integer.parseInt(b);
               PutLine(a);
          }});
     
     

     
     getContentPane().add(jScroll);
     getContentPane().add(ir);
     getContentPane().add(text);
     getContentPane().add(table);
    }
    
    public void PutLine(int a)
    {
     for(int i = 0; i < a; i++)
     {
      String b = Integer.toString(i);
      addLine("erro", b);
     }
    }
    
    
    public void addLine(String a, String b)
    {
     modelo.addRow(new String[]{a,b});
    }
    
    
    public static void main(String[] args) 
    {
     Loop frame = new Loop();
     frame.setVisible(true);
    }
}

Alguem sabe o porque?

Criado 20 de julho de 2012
Respostas 0
Participantes 1