2011-02-09 4 views
0

Java에서 Netbeans를 프로그래밍하고 있습니다.Java 테이블 포맷

환자 목록을 작성한 테이블이 있습니다. XML 파일의 정보를 읽었습니다.

package digiscope; 

import java.awt.event.MouseAdapter; 
import java.awt.event.MouseEvent; 
import java.io.File; 

/** 
* 
* @author Daniel 
*/ 
public class TabelaPaciente extends javax.swing.JPanel { 


String numero_processo; 
    int localizador = 0; 

    /** Creates new form TabelaPaciente */ 

    public TabelaPaciente() { 
     initComponents(); 
     load_table(); 
    } 

    public void setNumeroProc(String numero) { 
     numero_processo = numero; 
    } 

    public String getNumeroProc() { 
     return numero_processo; 
    } 

    public int getLocalizador() { 
     return localizador; 
    } 

    String[][] concat(String[][] A, String[][] B) { 
     String[][] C = new String[A.length + B.length][A.length + B.length]; 
     System.arraycopy(A, 0, C, 0, A.length); 
     System.arraycopy(B, 0, C, A.length, B.length); 

     return C; 
    } 

    private void load_table() { 

     File dir; 
     String[] filenames; 

     //dir = new File(System.getProperty("user.dir")+ "/XML"); 
     dir = new File(System.getProperty("user.dir") + "/Processos"); 

     filenames = dir.list(); 

     String[][] table_final = new String[][]{}; 

     for (int i = 0; i < filenames.length; i++) { 

      String n_proc = filenames[i];//filenames[i].substring(0,filenames[i].length()-4); 

      //System.out.println(filenames[i]); 

      Ler_XML xml = new Ler_XML(n_proc); 
      String nome_utente = xml.getNome(); 

      String[][] line = new String[][]{ 
       {n_proc, nome_utente, null, "ir para formulario"} 
      }; 

      table_final = concat(table_final, line); 
     } 

     tabela_pacientes.setModel(new javax.swing.table.DefaultTableModel(
       table_final, 
       new String[]{ 
        "Process Nº", "Name", "Date", "Form state" 
       })); 
    } 



    void executa_accao(int column, int row) { 

     if (column == 3) { 
      Object numero_proc = tabela_pacientes.getValueAt(row, 0); 

      localizador = 1; 

      numero_processo = numero_proc.toString(); 

      JanelaPrincipal cont = (JanelaPrincipal) this.getParent() // Internal Pane 
        .getParent() // ??? 
        .getParent() // ??? 
        .getParent() // ??? 
        .getParent(); // Frame 

      cont.loadPanel(new Formulario(1)); 

      Preencher_FormPaciente new_xml = new Preencher_FormPaciente(numero_processo, 1); 

     } 

    } 


    /** This method is called from within the constructor to 
    * initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is 
    * always regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code"> 
    private void initComponents() { 

     jScrollPane1 = new javax.swing.JScrollPane(); 
     tabela_pacientes = new javax.swing.JTable(); 
     btnMenu1 = new javax.swing.JButton(); 

     setPreferredSize(new java.awt.Dimension(1000, 550)); 

     tabela_pacientes.addMouseListener(new MouseAdapter() { 
      @Override 
      public void mouseClicked(MouseEvent event) { 
       int row = tabela_pacientes.rowAtPoint(event.getPoint()); 
       int column = tabela_pacientes.columnAtPoint(event.getPoint()); 
       if (row >= 0 && column >= 0) { 
        executa_accao(column, row); 
       } 
      } 
     }); 
     jScrollPane1.setViewportView(tabela_pacientes); 

     btnMenu1.setBackground(new java.awt.Color(255, 153, 0)); 
     btnMenu1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N 
     btnMenu1.setText("MENU"); 
     btnMenu1.setPreferredSize(new java.awt.Dimension(105, 75)); 
     btnMenu1.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       btnMenu1ActionPerformed(evt); 
      } 
     }); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 
     this.setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addContainerGap() 
       .addComponent(btnMenu1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addContainerGap(885, Short.MAX_VALUE)) 
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1000, Short.MAX_VALUE) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addContainerGap() 
       .addComponent(btnMenu1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addGap(18, 18, 18) 
       .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)) 
     ); 
    }// </editor-fold> 

    private void btnMenu1ActionPerformed(java.awt.event.ActionEvent evt) {           
      JanelaPrincipal cont = (JanelaPrincipal) this.getParent() // Internal Pane 
        .getParent() // ??? 
        .getParent() // ??? 
        .getParent() // ??? 
        .getParent(); // Frame 
      cont.loadPanel(new Menu()); 
    }           

    // Variables declaration - do not modify 
    private javax.swing.JButton btnMenu1; 
    private javax.swing.JScrollPane jScrollPane1; 
    private javax.swing.JTable tabela_pacientes; 
    // End of variables declaration 
} 

나는 그것이 문자의 크기를 증가시킬 수 있는지 알고 싶습니다 : 여기 당신은 코드가? 여기에서 표 미리보기를 볼 수 있습니다. enter image description here

협조 해 주셔서 감사합니다.

감사합니다.

답변

2

많은 경우에 테이블은 여러 렌더러를 사용하여 데이터를 렌더링합니다. String, Numbers, Dates 등 1 개. 디폴트 렌더러는 테이블의 Font를 사용해 텍스트를 렌더링한다. 모든 렌더러의 글꼴을 변경하려면 다음을 사용할 수 있습니다.

Font font = table.getFont(); 
table.setFont(font.deriveFont(24.0f)); 
table.setRowHeight(24); 

테이블 헤더에도이 작업을 수행 할 수 있습니다.

2

JTable의 셀 표시는 TableCellRenderer에 의해 제어됩니다. default 구현은 글꼴을 제어하는 ​​메소드가있는 JLabel에서 확장됩니다. 예를 들어 ...

DefaultTableCellRenderer newRenderer = new DefaultTableCellRenderer(); 
Font oldFont = newRenderer.getFont(); 
Font bigFont = new Font(oldFont.getName(),oldFont.getStyle(),24); 
newRenderer.setFont(bigFont); 
table.setDefaultRenderer(Object.class,newRenderer);