package JTabel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import javax.security.auth.callback.LanguageCallback;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.xml.ws.handler.MessageContext.Scope;
public class ResizeTable extends JFrame{
private JPanel contentpane;
private JPanel panel1;
private JPanel panel2;
private JTable table1;
private JTable table2;
/**
* @param args
* 表头与列高的设置
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ResizeTable frame=new ResizeTable();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
/*
* create the Jframe
*/
public ResizeTable()
{
setTitle("设置高度");
setBounds(100,100,450,250);
contentpane=new JPanel();
setContentPane(contentpane);
contentpane.setLayout(new GridLayout(1,2,5,5));
DefaultTableModel tablemodel=new DefaultTableModel();
tablemodel.setColumnIdentifiers(new Object[]{"排名","语言"});
tablemodel.addRow(new Object[]{"1","java"});
tablemodel.addRow(new Object[]{"2","c++"});
tablemodel.addRow(new Object[]{"3","c#"});
panel1=new JPanel(new BorderLayout());
contentpane.add(panel1);
panel1.add(new JLabel("默认表格"),BorderLayout.NORTH);
JScrollPane scrollPane1=new JScrollPane();
panel1.add(scrollPane1,BorderLayout.CENTER);
table1=new JTable(tablemodel);
scrollPane1.setViewportView(table1);
panel2=new JPanel(new BorderLayout());
JLabel label=new JLabel("自定义表格");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("微软雅黑",Font.PLAIN,16));
panel2.add(label,BorderLayout.NORTH);
contentpane.add(panel2);
JScrollPane srcollpanel2=new JScrollPane();
panel2.add(srcollpanel2,BorderLayout.CENTER);
table2=new JTable(tablemodel);
srcollpanel2.setViewportView(table2);
table2.setFont(new Font("微软雅黑",Font.PLAIN,14));
table2.setRowHeight(35); //设置高度
JTableHeader header=table2.getTableHeader();
header.setFont(new Font("微软雅黑",Font.PLAIN,16)); //字体
header.setPreferredSize(new Dimension(header.getWidth(),40));
}
}
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import javax.security.auth.callback.LanguageCallback;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.xml.ws.handler.MessageContext.Scope;
public class ResizeTable extends JFrame{
private JPanel contentpane;
private JPanel panel1;
private JPanel panel2;
private JTable table1;
private JTable table2;
/**
* @param args
* 表头与列高的设置
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ResizeTable frame=new ResizeTable();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
/*
* create the Jframe
*/
public ResizeTable()
{
setTitle("设置高度");
setBounds(100,100,450,250);
contentpane=new JPanel();
setContentPane(contentpane);
contentpane.setLayout(new GridLayout(1,2,5,5));
DefaultTableModel tablemodel=new DefaultTableModel();
tablemodel.setColumnIdentifiers(new Object[]{"排名","语言"});
tablemodel.addRow(new Object[]{"1","java"});
tablemodel.addRow(new Object[]{"2","c++"});
tablemodel.addRow(new Object[]{"3","c#"});
panel1=new JPanel(new BorderLayout());
contentpane.add(panel1);
panel1.add(new JLabel("默认表格"),BorderLayout.NORTH);
JScrollPane scrollPane1=new JScrollPane();
panel1.add(scrollPane1,BorderLayout.CENTER);
table1=new JTable(tablemodel);
scrollPane1.setViewportView(table1);
panel2=new JPanel(new BorderLayout());
JLabel label=new JLabel("自定义表格");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("微软雅黑",Font.PLAIN,16));
panel2.add(label,BorderLayout.NORTH);
contentpane.add(panel2);
JScrollPane srcollpanel2=new JScrollPane();
panel2.add(srcollpanel2,BorderLayout.CENTER);
table2=new JTable(tablemodel);
srcollpanel2.setViewportView(table2);
table2.setFont(new Font("微软雅黑",Font.PLAIN,14));
table2.setRowHeight(35); //设置高度
JTableHeader header=table2.getTableHeader();
header.setFont(new Font("微软雅黑",Font.PLAIN,16)); //字体
header.setPreferredSize(new Dimension(header.getWidth(),40));
}
}