1.WindowBuilder安装
这个Eclipse插件能够实现在Java Swing编程中各种控件的拖拽
下载地址:http://www.eclipse.org/windowbuilder/download.php
Eclipse 3.7的安装方法(其它版本Eclipse类似):http://download.eclipse.org/windowbuilder/WB/release/R201309271200/3.7/
2.使JPanel成为JDialog的父窗口
JPanel panel = new JPanel(); Window parentWindow = SwingUtilities.windowForComponent(panel); Frame parentFrame = (Frame)parentWindow; JDialog dialog = new JDialog(parentFrame); ...
JComboBox<String> myComboBox = new JComboBox<String>(array); myJTable.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(myComboBox));
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);// 最大化
//获得屏幕宽度 public double getScreenWidth(){ return Toolkit.getDefaultToolkit().getScreenSize().getWidth(); } //获得屏幕高度 public double getScreenHeight(){ return Toolkit.getDefaultToolkit().getScreenSize().getHeight(); } //将Frame居中 public void setFrameOnCenter(Window win){ Window window = win; int width = (int) getScreenWidth(); int height = (int) getScreenHeight(); window.setLocation((width - window.getWidth()) / 2, (height - window.getHeight()) / 2); }
((TitledBorder)panel.getBorder()).setTitleFont(new Font("宋体", Font.BOLD, 16));
7.在JPanel中设置背景图片
JLabel lblNewLabel = new JLabel(""); lblNewLabel.setIcon(new ImageIcon(Panel.class.getResource("/images/welcome.jpg")));
images是在src目录下创建的包
8. 设置JTable中某一列不可编辑
DefaultTableModel中有个方法 public boolean isCellEditable(int row, int column),无论参数是多少该方法都返回true,如果要设置某一列不可编辑,可以在创建DefaultTableModel时这样做:
DefaultTableModel trainFormationTableModel = new DefaultTableModel(columnNamesVector, 0){ public boolean isCellEditable(int row, int column){ if(column == 0){ return false; } return true; } };上面这段代码是设置第一列不可编辑
9. JTable单元格失去焦点前提交
在编辑Java Swing JTable单元格时,默认情况下,要在被编辑单元格失去焦点后才能提交该数据,失去焦点前,单元格的数据无法被读取到,加入如下属性可解决此问题:
table.putClientProperty("terminateEditOnFocusLost", true);
10. JPanel动态添加组件不显示问题
在JPanel中动态添加组件之后,需要调用jpanel.updateUI()方法
11. jfreechartt中文乱码
http://my.oschina.net/bairrfhoinn/blog/159535