Guest User

Untitled

a guest
Oct 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import javax.swing.JDialog;
  2. import javax.swing.JFrame;
  3. import javax.swing.JTable;
  4. import javax.swing.UIManager;
  5. import javax.swing.UnsupportedLookAndFeelException;
  6. import javax.swing.table.TableColumnModel;
  7.  
  8. /**
  9. * Swing helper for column of JTable
  10. * @author keating_andy_given
  11. */
  12. public class CSHelp {
  13.  
  14. /**
  15. * 设置JTable的列宽
  16. */
  17. public static void columnWidth(JTable table, int width) {
  18. TableColumnModel columnModel = table.getColumnModel();
  19. for(int i = 0; i < columnModel.getColumnCount(); i ++){
  20. columnModel.getColumn(i).setPreferredWidth(width);
  21. }
  22. }
  23.  
  24. /**
  25. * 设置JTable某一列的列宽
  26. * @param table
  27. * @param width
  28. */
  29. public static void columnWidth(JTable table, int columnNumber, int width) {
  30. table.getColumnModel()
  31. .getColumn(columnNumber).setPreferredWidth(width);
  32. }
  33.  
  34. /**
  35. * 隐藏JTable第一列
  36. */
  37. public static void hideFirstColumn(JTable table) {
  38. table.removeColumn(table.getColumnModel().getColumn(0));
  39. }
  40.  
  41. /**
  42. * 设置style
  43. */
  44. public static void style() {
  45. JFrame.setDefaultLookAndFeelDecorated(true);
  46. JDialog.setDefaultLookAndFeelDecorated(true);
  47. try {
  48. UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());//windows样式
  49. } catch (UnsupportedLookAndFeelException ex) {
  50. Logger.getLogger(CSHelp.class.getName()).log(Level.SEVERE, null, ex);
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment