zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package PbuliClass;
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;
 
import ColorAndFont.UIColor;
import Method.FenseRenderer;
 
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.CENTER);
        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;   
 
    }
 
 
}