JFrame display problem

Hi All,

My JFrame has 3 big tables and few label and text fields. It clips some rows in table while displaying and if I usemaximun resulution then it displays properly.

Is it because of the layout I am using or because og the big size of the table?

Is there way to shrink the table size?

Folowing is code ( sorry for such a huge file )

import javax.swing.border.*;

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.table.*;

import javax.swing.*;

public class Graph_Page_I extends javax.swing.JFrame {

// Variables declaration - do not modify

privateJPanel jPanel1,jPanel1a,jPanel1b,jPanel1c,jPanel1d,jPanel2,jPanel2a,jPanel2b,jPanel2aa,jPanel2ab,jPanel2ba,jPanel2bb,jPanel3,jPanel3a,jPanel3b,jPanel12;

privateJLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8,jLabel9,jLabel10;

privateJTextField jTextField1,jTextField2,jTextField3,jTextField4;

privateJTable jTable1,jTable2,jTable3;

// End of variables declaration

/** Creates new form Graph_Page_I */

public Graph_Page_I() {

initComponents();

}

private void initComponents() {

jPanel1 = new JPanel();

jPanel1a = newJPanel();

jLabel1 = newJLabel();

jLabel2 = newJLabel();

jTextField1 = newJTextField(7);

jPanel1b = newJPanel();

jLabel3 = newJLabel();

jTextField2 = newJTextField(7);

jPanel1c = newJPanel();

jLabel4 = newJLabel();

jTextField3 = newJTextField(7);

jLabel5 = newJLabel();

jPanel1d = newJPanel();

jLabel6 = newJLabel();

jTextField4 = newJTextField(7);

jLabel7 = newJLabel();

jPanel3 = newJPanel();

jPanel3a = newJPanel();

jLabel10 = newJLabel();

jPanel3b = newJPanel();

jTable1 = newJTable();

jTable2 = newJTable();

jTable3 = newJTable();

jPanel12 = newJPanel();

jPanel2 = newJPanel();

jPanel2a = newJPanel();

jPanel2aa = newJPanel();

jLabel8 = newJLabel();

jPanel2ab = newJPanel();

jPanel2b = newJPanel();

jPanel2ba = newJPanel();

jLabel9 = newJLabel();

jPanel2bb = newJPanel();

setTitle("GraphPage I");

setBackground(java.awt.Color.white);

addWindowListener(new java.awt.event.WindowAdapter() {

public void windowClosing(java.awt.event.WindowEvent evt) {

exitForm(evt);

}

});

jPanel1a.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));

jPanel1b.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));

jPanel1c.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));

jPanel1d.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));

jPanel2aa.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));

jPanel2ba.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));

jPanel3a.setLayout(new java.awt.GridLayout(4, 0));

jLabel1.setText("Enter ");

jPanel1a.add(jLabel1);

jLabel2.setText("Name of Laboratory:");

jPanel1a.add(jLabel2);

jTextField1.setText("");

jPanel1a.add(jTextField1);

jPanel1.setLayout(new java.awt.GridLayout(4, 0));

jPanel1.add(jPanel1a);

jLabel3.setText(" Date:");

jPanel1b.add(jLabel3);

jTextField2.setText("");

jPanel1b.add(jTextField2);

jPanel1.add(jPanel1b);

jLabel4.setText(" Run Number(1 or 2):");

jPanel1c.add(jLabel4);

jTextField3.setText("");

jPanel1c.add(jTextField3);

jLabel5.setText("Please enter the run number (1or 2) in cell F3");

jPanel1c.add(jLabel5);

jPanel1.add(jPanel1c);

jLabel6.setText(" Temperature of room where assay was run(C)");

jPanel1d.add(jLabel6);

jTextField4.setText("");

jPanel1d.add(jTextField4);

jLabel7.setText("Outside Recommended Range(18-27)!");

jPanel1d.add(jLabel7);

jPanel1.add(jPanel1d);

getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

jPanel3.setLayout(new java.awt.BorderLayout());

jLabel10.setText("Enter OD Values according to Figure 1");

jPanel3a.add(jLabel10);

// jPanel3.add(jPanel3a, java.awt.BorderLayout.NORTH );

jPanel3.add(jLabel10, java.awt.BorderLayout.NORTH );

jTable3.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},

{"A", null, null, null, null, null, null, null, null, null, null, null, null},

{"B", null, null, null, null, null, null, null, null, null, null, null, null},

{"C", null, null, null, null, null, null, null, null, null, null, null, null},

{"D", null, null, null, null, null, null, null, null, null, null, null, null},

{"E", null, null, null, null, null, null, null, null, null, null, null, null},

{"F", null, null, null, null, null, null, null, null, null, null, null, null},

{"G", null, null, null, null, null, null, null, null, null, null, null, null},

{"H", null, null, null, null, null, null, null, null, null, null, null, null}

},

new String [] {

"Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7", "Title 8", "Title 9", "Title 10", "Title 11", "Title 12", "Title 13"

}

) {

Class[] types = new Class [] {

java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class

};

public Class getColumnClass(int columnIndex) {

return types [columnIndex];

}

});

jPanel3b.add(jTable3);

jPanel3b.add(jPanel12);

jPanel3.add(jPanel3b, java.awt.BorderLayout.CENTER);

getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);

jPanel2.setLayout(new java.awt.GridLayout(2, 0));

jPanel2a.setLayout(new java.awt.BorderLayout());

jLabel8.setText("Figure 1. Sample Layout");

jPanel2aa.add(jLabel8);

jPanel2a.add(jPanel2aa, java.awt.BorderLayout.NORTH );

DefaultTableModel dm = new DefaultTableModel()

{

public Class getColumnClass(int columnIndex)

{

return String.class;

}

};

dm.setDataVector(new Object [][] {

{"A", "0% STD\nRep 1","0% STD\nRep 2","0.3% STD\nRep 1","0.3% STD\nRep 2","1.25% STD\nRep 1","1.25% STD\nRep 2","2.5% STD\nRep 1","2.5% STD\nRep 2","Sample1\nRep 1","Sample1\n Rep2","Sample2\nRep 1","Sample2\n Rep 2"},

{"B", "Sample3\nRep 1","Sample3\n Rep 2", "Sample4\nRep 1","Sample4\n Rep 2", "Sample5\nRep 1","Sample5\n Rep 2", "Sample6\nRep 1","Sample6\n Rep 2", "Sample7\nRep 1","Sample7\n Rep 2", "Sample8\nRep 1","Sample8\n Rep 2"},

{"C", "Sample9\nRep 1","Sample9\n Rep 2", "Sample10\nRep 1","Sample10\n Rep 2", "Sample11\nRep 1","Sample11\n Rep 2", "Sample12\nRep 1","Sample12\n Rep 2", "Sample13\nRep 1","Sample13\n Rep 2", "Sample14\nRep 1","Sample14\n Rep 2"},

{"D", "Sample15\nRep 1","Sample15\n Rep 2", "Sample16\nRep 1","Sample16\n Rep 2", "Sample17\nRep 1","Sample17\n Rep 2", "Sample18\nRep 1","Sample18\n Rep 2", "Sample19\nRep 1","Sample19\n Rep 2", "Sample20\nRep 1","Sample21\n Rep 2"},

{"E", "Sample21\nRep 1","Sample21\n Rep 2", "Sample22\nRep 1","Sample22\n Rep 2", "Sample23\nRep 1","Sample23\n Rep 2", "Sample24\nRep 1","Sample24\n Rep 2", "Sample25\nRep 1","Sample25\n Rep 2", "Sample26\nRep 1","Sample26\n Rep 2"},

{"F", "Sample27\nRep 1","Sample27\n Rep 2", "Sample28\nRep 1","Sample28\n Rep 2", "Sample29\nRep 1","Sample29\n Rep 2", "Sample30\nRep 1","Sample30\n Rep 2", "Sample31\nRep 1","Sample31\n Rep 2", "Sample32\nRep 1","Sample32\n Rep 2"},

{"G", "Sample33\nRep 1","Sample33\n Rep 2", "Sample34\nRep 1","Sample34\n Rep 2", "Sample235\nRep 1","Sample35\n Rep 2", "Sample36\nRep 1","Sample36\n Rep 2", "Sample37\nRep 1","Sample37\n Rep 2", "Sample38\nRep 1","Sample38\n Rep 2"},

{"H", "Sample39\nRep 1","Sample39\n Rep 2", "Sample40\nRep 1","Sample40\n Rep 2", "Sample41\nRep 1","Sample41\n Rep 2", "Sample42\nRep 1","Sample42\n Rep 2", "Sample43\nRep 1","Sample43\n Rep 2", "Sample44\nRep 1","Sample44\n Rep 2"},

},

new String [] {" ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"});

jTable1 = new JTable( dm );

int lines = 2;

jTable1.setRowHeight( jTable1.getRowHeight() * lines);

jTable1.setDefaultRenderer(String.class, new MultiLineCellRenderer());

jPanel2ab.add(jTable1);

jPanel2a.add(jPanel2ab, java.awt.BorderLayout.CENTER);

jPanel2.add(jPanel2a);

jLabel9.setText("Enter the Sample Identification Number according to Figure 1");

jPanel2ba.add(jLabel9);

jPanel2b.add(jPanel2ba,java.awt.BorderLayout.NORTH);

// jPanel2bb.setLayout(new java.awt.BorderLayout());

jTable2.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},

{"A", null, null, null, null, null, null, null, null, null, null, null, null},

{"B", null, null, null, null, null, null, null, null, null, null, null, null},

{"C", null, null, null, null, null, null, null, null, null, null, null, null},

{"D", null, null, null, null, null, null, null, null, null, null, null, null},

{"E", null, null, null, null, null, null, null, null, null, null, null, null},

{"F", null, null, null, null, null, null, null, null, null, null, null, null},

{"G", null, null, null, null, null, null, null, null, null, null, null, null},

{"H", null, null, null, null, null, null, null, null, null, null, null, null}

},

new String [] {

"Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7", "Title 8", "Title 9", "Title 10", "Title 11", "Title 12", "Title 13"

}

));

jPanel2bb.add(jTable2);

jPanel2b.add(jPanel2bb, java.awt.BorderLayout.CENTER);

jPanel2.add(jPanel2b);

getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

pack();

}

/** Exit the Application */

private void exitForm(java.awt.event.WindowEvent evt) {

System.exit(0);

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

new Graph_Page_I().show();

}

}

/**MultiLineCellRenderer prgram **/

import javax.swing.*;

import javax.swing.table.*;

import javax.swing.border.*;

import java.awt.*;

public class MultiLineCellRenderer extends JTextArea implements TableCellRenderer {

public MultiLineCellRenderer() {

setLineWrap(true);

setWrapStyleWord(true);

setOpaque(true);

}

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

{

if (isSelected)

{

setForeground(table.getSelectionForeground());

setBackground(table.getSelectionBackground());

}

else

{setForeground(table.getForeground());

setBackground(table.getBackground());

}setFont(table.getFont());

if (hasFocus)

{

setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );

if (table.isCellEditable(row, column))

{

setForeground( UIManager.getColor("Table.focusCellForeground") );

setBackground( UIManager.getColor("Table.focusCellBackground") );

}

}

else

{setBorder(new EmptyBorder(1, 2, 1, 2));

}

setText((value == null) ? "" : value.toString());

return this;

}

}

[11832 byte] By [padma_patila] at [2007-9-19]
# 1
Hi,You defined in a hard way rather than doing it in a simple way. I felt you are using more panels. If I find anything else or if I come across a good way..I will let you know.
aachia at 2007-7-8 > top of java,Archived Forums,Swing [Archive]...