swing - Java table formatting -
i’im programing in java netbeans.
i have table list patients. read information in xml file. here have code:
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[][]{}; (int = 0; < 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); } } /** method called within constructor * initialize form. * warning: not modify code. content of method * regenerated 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 - not modify private javax.swing.jbutton btnmenu1; private javax.swing.jscrollpane jscrollpane1; private javax.swing.jtable tabela_pacientes; // end of variables declaration }
i know if it’s possible increase letter size? can see here preview of table.
thank collaboration.
best regards.
in many cases table use multiple renderers render data. 1 strings, numbers, dates etc. default renderers use font of table render text. change font renderers can use:
font font = table.getfont(); table.setfont( font.derivefont(24.0f) ); table.setrowheight(24);
you can table header well.
Comments
Post a Comment