Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JTable;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- import javax.swing.table.TableColumnModel;
- /**
- * Swing helper for column of JTable
- * @author keating_andy_given
- */
- public class CSHelp {
- /**
- * 设置JTable的列宽
- */
- public static void columnWidth(JTable table, int width) {
- TableColumnModel columnModel = table.getColumnModel();
- for(int i = 0; i < columnModel.getColumnCount(); i ++){
- columnModel.getColumn(i).setPreferredWidth(width);
- }
- }
- /**
- * 设置JTable某一列的列宽
- * @param table
- * @param width
- */
- public static void columnWidth(JTable table, int columnNumber, int width) {
- table.getColumnModel()
- .getColumn(columnNumber).setPreferredWidth(width);
- }
- /**
- * 隐藏JTable第一列
- */
- public static void hideFirstColumn(JTable table) {
- table.removeColumn(table.getColumnModel().getColumn(0));
- }
- /**
- * 设置style
- */
- public static void style() {
- JFrame.setDefaultLookAndFeelDecorated(true);
- JDialog.setDefaultLookAndFeelDecorated(true);
- try {
- UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());//windows样式
- } catch (UnsupportedLookAndFeelException ex) {
- Logger.getLogger(CSHelp.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Add Comment
Please, Sign In to add comment