建立一个 Derby 日历,第 3 部分: 使用事务和锁定(下)
2010-04-19 00:00:00 来源:WEB开发网这些元素基本上与第 2 部分中添加的元素相同,但是布局更加合理了(参见 图 2)。
图 2. 基本的输入表单
查看原图(大图)
日历选择器
这是最有趣的地方,至少从 GUI 的角度来看如此。不再让用户操作多个下拉菜单并期望选择的日期是合法的,我们添加了一个日历选择器,如 清单 23 所示。
清单 23. 添加日历选择器
...
private JComponent layoutLeftPanel() {
// Calendar picker
JPanel pickerPanel = new JPanel(new BorderLayout());
JPanel titlePanel = new JPanel();
titlePanel.add(new JLabel("<html><h3>Select a Date</h3></html>"));
pickerPanel.add(titlePanel, BorderLayout.NORTH);
JSplitPane viewSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
this.calendarPicker = new JCalendar();
pickerPanel.add(this.calendarPicker, BorderLayout.CENTER);
viewSplitPane.setTopComponent(pickerPanel);
this.calendarPicker.addPropertyChangeListener(this);
// Edit Panel
JPanel editPanel = new JPanel(new GridBagLayout());
GridBagConstraints cons = new GridBagConstraints();
cons.fill = GridBagConstraints.HORIZONTAL;
cons.anchor = GridBagConstraints.PAGE_START;
cons.insets = new Insets(5, 2, 5, 2);
cons.ipadx = 2;
cons.ipady = 2;
int rows = 1;
cons.weightx = 0.5;
cons.gridwidth = 1;
cons.gridy = rows++;
editPanel.add(new JLabel("Date: "), cons);
cons.gridx = 1;
final JDateChooser dateChooser = new JDateChooser();
editPanel.add(dateChooser, cons);
cons.gridy = rows++;
cons.gridx = 0;
editPanel.add(new JLabel("Title:"), cons);
...
更多精彩
赞助商链接