package publicclass;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

public class greateTables {
	int tableRowCount;//±í¸ñµÄ×ÜÐÐÊý
	int tableColumnCount;//±í¸ñ×ÜÁÐÊý
	String tableColumnName;//±í¸ñijһÁÐÃû
	Vector<String> columnNames;//±í¸ñÁÐÃû¼¯ºÏ
	Vector<Vector<String>> rowData;//±í¸ñÐÐÊý¾Ý
	DefaultTableModel tableModel;//´´½¨±í¸ñÄ£ÐÍ



	public greateTables(){//¿Õ¹¹Ôì·½·¨

	}



	public JTable greateTable( DefaultTableModel tableModel){//´´½¨±í¸ñ	 

		JTable table=new JTable(tableModel);
		table.setShowGrid(true);// »æÖÆÍø¸ñÏß
		table.setBackground(UIColor.getNorth_color());
		table.setSelectionForeground(Color.blue);//Ñ¡ÖеÄÎÄ×ÖÑÕɫΪÀ¶É«
		table.setSelectionBackground(UIColor.getTable_sekected());//Ñ¡ÖÐÐеı³¾°É«
		table.setShowHorizontalLines(true);  //ˮƽÏß²»ÏÔʾ
		table.setShowVerticalLines(true); //´¹Ö±Ïß²»ÏÔʾ
		//table.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		// ÉèÖñí¸ñÄ£Ð͵ı߿òÑùʽ
		table.setRowHeight(25);//ÉèÖñí¸ñÐиß25ÏñËØ 




		/*---------ÒÔÏ´úÂëΪÉèÖñí¸ñµ¥Ôª¸ñÄÚÈݾÓÖÐÏÔʾ´úÂë----------------*/

		DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
		tcr.setHorizontalAlignment(SwingConstants.LEFT);
		table.setDefaultRenderer(Object.class, tcr);


		/*---------ΪÉèÖñí¸ñµ¥Ôª¸ñÄÚÈݾÓÖÐÏÔʾ´úÂë½áÊø----------------*/
		//table.setDefaultRenderer(Object.class, new FenseRenderer());

		return table;   

	}

	public static JTable creat_table( DefaultTableModel tableModel,int left){//´´½¨±í¸ñ	 

		JTable table=new JTable(tableModel);
		table.setShowGrid(true);// »æÖÆÍø¸ñÏß
		table.setSelectionForeground(Color.blue);//Ñ¡ÖеÄÎÄ×ÖÑÕɫΪÀ¶É«
		table.setSelectionBackground(UIColor.getTable_sekected());//Ñ¡ÖÐÐеı³¾°É«
		//	   table.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));// ÉèÖñí¸ñÄ£Ð͵ı߿òÑùʽ
		table.setRowHeight(25);//ÉèÖñí¸ñÐиß25ÏñËØ 



		/*---------ÒÔÏ´úÂëΪÉèÖñí¸ñµ¥Ôª¸ñÄÚÈݾÓÖÐÏÔʾ´úÂë----------------*/

		DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
		if(left==0) {
			tcr.setHorizontalAlignment(SwingConstants.LEFT);
		}else {
			tcr.setHorizontalAlignment(SwingConstants.LEFT);  
		}
		table.setDefaultRenderer(Object.class, tcr);

		/*---------ΪÉèÖñí¸ñµ¥Ôª¸ñÄÚÈݾÓÖÐÏÔʾ´úÂë½áÊø----------------*/


		return table;   

	}
	/**Õ¤À¸Ð§¹û±í¸ñ*/
	public JTable getTable( DefaultTableModel tableModel){//´´½¨±í¸ñ	 

		JTable table=new JTable(tableModel);
		table.setShowGrid(true);// »æÖÆÍø¸ñÏß
		table.setBackground(UIColor.getNorth_color());	
		table.setShowHorizontalLines(false);  //ˮƽÏß²»ÏÔʾ
		table.setShowVerticalLines(true); //´¹Ö±Ïß²»ÏÔʾ
		table.setBorder(BorderFactory.createLineBorder(UIColor.getNorth_color()));
		// ÉèÖñí¸ñÄ£Ð͵ı߿òÑùʽ
		table.setRowHeight(40);//ÉèÖñí¸ñÐиß25ÏñËØ 
		table.setGridColor(Color.white);
		table.setSelectionBackground(UIColor.getTable_sekected());//Ñ¡ÖÐÐеı³¾°É«
		/*---------ÒÔÏ´úÂëΪÉèÖñí¸ñµ¥Ôª¸ñÄÚÈݾÓÖÐÏÔʾ´úÂë----------------*/
		table.setDefaultRenderer(Object.class, new FenseRenderer());

		//		table.addAncestorListener(new AncestorListener);

		Dimension size = table.getTableHeader().getPreferredSize();
		//ÉèÖñí¸ñ±êÌâÀ¸ÑÕÉ«
		table.getTableHeader().setBackground(UIColor.getNorth_color());
		size.height =32;//ÉèÖÃеıíÍ·¸ß¶È32
		table.getTableHeader().setPreferredSize(size);

		//ÉèÖñí¸ñ±êÌâ×ÖÌå
		table.getTableHeader().setFont(new Font("TimesRoman", Font.BOLD, 13));

		return table;   

	}


}