Tamanho tabela maior que o de exibição

6 respostas
D

[size=“12”][/size]

OI gente sou novo aki no portal, procurei pra kramba mas não encontrei então desculpe-me se já existir um tópico igual a este…

Eu estou querendo imprimir uma tabela so que ela é muito grande(12 colunas) e cada coluna tbm é um pouco grande(Nome Completo,Endereço)…eu até consigo fazer ela aparecer toda só que fica toda esprimida e não da pra ler nada ou então eu coloco sem ser esprimida só que não aparece ela toda…já tentei coloca- la dentro de uma JScrollPane mas não deu certo(1° caso), as vezes eu estou fazendo alguma coisa errada…será que alguem pode me ajudar??

Desde de já fico muito agradecido…fwls :?: :?: :?:

6 Respostas

D

“daniloliveirabr”:
[size=“12”][/size]

OI gente sou novo aki no portal, procurei pra kramba mas não encontrei então desculpe-me se já existir um tópico igual a este…

Eu estou querendo imprimir uma tabela so que ela é muito grande(12 colunas) e cada coluna tbm é um pouco grande(Nome Completo,Endereço)…eu até consigo fazer ela aparecer toda só que fica toda esprimida e não da pra ler nada ou então eu coloco sem ser esprimida só que não aparece ela toda…já tentei coloca- la dentro de uma JScrollPane mas não deu certo(1° caso), as vezes eu estou fazendo alguma coisa errada…será que alguem pode me ajudar??

Desde de já fico muito agradecido…fwls :?: :?: :?:

Pq vc tem que imprimir direto da JTable ?
:idea: Que tal fazer um relatório contendo todos campos da tabela !
O que acha :?:

D

Não entendi o que vc quis dizer com fazer um relatório contendo os campos da tabela, tipo assim vc fala fazer tipo que uma impressão de uma ficha contendo os campos da tabela???..e tbm tem outra coisa eu me expressei mal eu não queria direto da JTable…e sim eu quero imprimir em uma JTable…só que ela fica toda espremida…e eu queria que cada campo se mostra-se por inteiro…entendeu???

D

Achei que vc queri imprimir os dados, mas acho que vc quer mostrar os dados na tela , estou certo ?
Pois bem, existe no livro do Deitel um exemplo que vai ser útil pra vc.
Caso não tenha o livro posso te mandar o código mais tarde.
Ele cria um JTable já com Scroll contendo os campos de uma tabela.

Um abraço !

Só uma pergunta , vc setou o tamanho dos campos da sua tabela ?

D

Por favor manda os códigos pra min…eu não tenho o livro…faz esse favorzão pra mim…vou ficar t devendo uma em…brigadão…fwls

D

Eu coloco o código aqui mais tarde então !
Disponha :!:

D

Eu coloco o código aqui mais tarde então !
Disponha :!:

// Fig. 18.24: TableDisplay.java
// This program displays the contents of the Authors table
// in the Books database.
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class TableDisplay extends JFrame {
   private Connection connection;
   private JTable table;
    
   public TableDisplay() 
   {   
      // The URL specifying the Books database to which 
      // this program connects using JDBC to connect to a
      // Microsoft ODBC database.
      String url = "jdbc:odbc:Books";  
      String username = "anonymous";
      String password = "guest";

      // Load the driver to allow connection to the database
      try {
         Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

         connection = DriverManager.getConnection( 
            url, username, password );
      } 
      catch ( ClassNotFoundException cnfex ) {
         System.err.println( 
            "Failed to load JDBC/ODBC driver." );
         cnfex.printStackTrace();
         System.exit( 1 );  // terminate program
      }
      catch ( SQLException sqlex ) {
         System.err.println( "Unable to connect" );
         sqlex.printStackTrace();
      }

      getTable();

      setSize( 450, 150 );
      show();
   }

   private void getTable()
   {
      Statement statement;
      ResultSet resultSet;
      
      try {
         String query = "SELECT * FROM Authors";

         statement = connection.createStatement();
         resultSet = statement.executeQuery( query );
         displayResultSet( resultSet );
         statement.close();
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
      }
   }

   private void displayResultSet( ResultSet rs )
      throws SQLException
   {
      // position to first record
      boolean moreRecords = rs.next();  

      // If there are no records, display a message
      if ( ! moreRecords ) {
         JOptionPane.showMessageDialog( this, 
            "ResultSet contained no records" );
         setTitle( "No records to display" );
         return;
      }

      setTitle( "Authors table from Books" );

      Vector columnHeads = new Vector();
      Vector rows = new Vector();

      try {
         // get column heads
         ResultSetMetaData rsmd = rs.getMetaData();
      
         for ( int i = 1; i <= rsmd.getColumnCount(); ++i ) 
            columnHeads.addElement( rsmd.getColumnName( i ) );

         // get row data
         do {
            rows.addElement( getNextRow( rs, rsmd ) ); 
         } while ( rs.next() );

         // display table with ResultSet contents
         table = new JTable( rows, columnHeads );
         JScrollPane scroller = new JScrollPane( table );
         getContentPane().add( 
            scroller, BorderLayout.CENTER );
         validate();
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
      }
   }

   private Vector getNextRow( ResultSet rs, 
                              ResultSetMetaData rsmd )
       throws SQLException
   {
      Vector currentRow = new Vector();
      
      for ( int i = 1; i <= rsmd.getColumnCount(); ++i )
         switch( rsmd.getColumnType( i ) ) {
            case Types.VARCHAR:
                  currentRow.addElement( rs.getString( i ) );
               break;
            case Types.INTEGER:
                  currentRow.addElement( 
                     new Long( rs.getLong( i ) ) );
               break;
            default: 
               System.out.println( "Type was: " + 
                  rsmd.getColumnTypeName( i ) );
         }
      
      return currentRow;
   }

   public void shutDown()
   {
      try {
         connection.close();
      }
      catch ( SQLException sqlex ) {
         System.err.println( "Unable to disconnect" );
         sqlex.printStackTrace();
      }
   }

   public static void main( String args[] ) 
   {
      final TableDisplay app = new TableDisplay();

      app.addWindowListener( 
         new WindowAdapter() {
            public void windowClosing( WindowEvent e ) 
            {  
               app.shutDown();
               System.exit( 0 );
            }
         }
      );
   }
}

/**************************************************************************
 * (C) Copyright 1999 by Deitel & Associates, Inc. and Prentice Hall.     *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

o banco de dados para usar no exemplo te mando no email…manda um email pra mim…que dou reply com ele…

Um Abraço !

Criado 9 de maio de 2006
Ultima resposta 11 de mai. de 2006
Respostas 6
Participantes 2