对于延迟,我深表歉意,但我还有其他更紧迫的承诺。
正如所承诺的,这里是一个演示,展示了如何利用 InventoryDemo 类中包含的方法来处理与您在帖子中显示的内容相似 的表单。
这个可运行的演示应用程序是一个快速的作品,所以不要指望任何真正的优化。当您创建自己的应用程序时,这将取决于您。简单性有助于提高理解能力。
下面的可运行演示(名为DB_GUI)利用了我的previous post 中提供的类:
- InventoryItems 类 (InventoryItems.java)
- InventoryDemo 类 (InventoryDemo.java)
对 InventoryDemo 类进行了非常小的调整,并更新了我的 previous post 中的代码。
这个runnable的工作方式如下:
您从一个空白数据库(没有文本文件)开始。文本数据文件会根据需要自动创建,每个文件代表一个特定的库存类别,例如:书写工具、游戏机等。这些类别是通过可编辑 JComboBox 位于应用程序窗口的顶部。如果此 JComboBox 中提供的类别未已包含在组合列表中,则将其添加到该列表中,并创建一个数据文件以准备保存与该特定类别相关的库存项目。
数据文件是在名为 InventoryCategories 的目录中创建的,该目录是在您的本地文件系统中自动创建的,位于您运行特定应用程序的驱动器的 root 目录中. 在尝试运行此演示应用程序之前,请确保此类操作存在适当的权限。
要在表单的 JTextFields 中创建类别和编辑、添加、保存或删除数据,必须获得管理员访问权限。普通用户可以修改的唯一数据项是 Quantity 字段。要进入管理员模式,请选择 JTable 正下方的 Admin 链接。您将需要输入当前为 1234 的密码。您可以通过修改下面代码中的 ADMIN_PASSWORD 类字段变量中包含的字符串值来将此密码更改为您喜欢的任何密码。
在管理员模式下:
- 要编辑库存项目,从表中选择它,然后执行
您喜欢从 JTextFields 进行的任何编辑。完成编辑和
要保存您的工作,请选择 保存 按钮。
- 要将库存项目添加到当前活动类别,请选择
添加按钮。所有 JTextField 都将清除。供应
表单的 JTextFields 中所需的数据,然后在完成后选择
保存按钮。该记录将被保存(附加)到
相关数据文件并放入JTable。提供项目 ID
是可选的,因为如果未提供 ID,则会自动生成
起始 ID 为 00001。您不能提供重复的 ID 值
在同一类别中。
- 要从当前活动类别中删除库存项目,请选择
JTable 中所需的库存项目,该项目将是
显示在位于底部的 JTextField 中
形式。选择 删除 按钮。确认对话框是
显示,选择 Yes 按钮确认删除,然后选择
从数据文件和 JTable 中删除库存项目。
退出管理员模式:
只需再次选择位于 JTable 底部的 Admin 链接。此链接是进入和退出管理员模式的开关。
申请代码:
/*
Data text file names are based from the names of the categoryies
created in Form. If a 'Writing Instruments' category is created
then the data file created for that category's date will be named:
Writing Instruments.txt
If a 'Game Consoles' category is created then the data file created
for that category's date will be named:
Game Consoles.txt
and so on. Categories are created by entering a specific category
name (that DOES NOT already exist) into the Categories Drop-Down
List (comboBox).
*/
package inventorydemo;
import com.sun.glass.events.KeyEvent;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
public class DB_GUI extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
private final InventoryDemo demo = new InventoryDemo();
private final String ADMIN_PASSWORD = "1234";
private boolean appStarted = false;
public DB_GUI() {
initComponents();
fillCategoriesCombo();
categoryComboBox.setSelectedIndex(-1);
// Set the JTable's Header font size to match the JTable's font size.
JTableHeader header = jTable1.getTableHeader();
header.setFont(header.getFont().deriveFont((float) jTable1.getFont().getSize()));
// Center Text in JTable Header Cells.
alignJTableHeaderText(jTable1, 0);
// Set JTable's Column Widths
setJTableColumnWidths(jTable1, 13d, 62d, 15d, 10d);
// Set JTable's background color to White.
jTable1.setFillsViewportHeight(true);
jScrollPane1.getViewport().setBackground(Color.white);
// Modifying the Look & Feel
// Set JTable Header Background color to White.
UIManager.getDefaults().put("TableHeader.background", Color.WHITE);
// Remove JTable Header borders
UIManager.getDefaults().put("TableHeader.cellBorder", BorderFactory.createEmptyBorder(0, 0, 0, 0));
// Set JTextField's inactive background color to White.
UIManager.getDefaults().put("TextField.inactiveBackground", Color.WHITE);
// Key Binding for Category Combo. Passes what was entered to
// the addNewCategory() method when the ENTER key is pressed.
// Used to add new Categories.
categoryComboBox.getEditor().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (demo.isInAdminMode()) {
addNewCategory(categoryComboBox.getEditor().getItem().toString());
}
else {
JFrame iFrame = new JFrame();
iFrame.setAlwaysOnTop(true);
iFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
iFrame.setLocationRelativeTo(null);
JOptionPane.showMessageDialog(iFrame, "You need Admin Access to "
+ "create categories!", "Admin Required!", JOptionPane.WARNING_MESSAGE);
iFrame.dispose();
}
}
});
// Center text in ComboBox.
((JLabel) categoryComboBox.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
// Set startup focus to the Admin link.
lblAdminAccess.requestFocus();
appStarted = true;
}
@SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
productNameBox = new javax.swing.JTextField();
categoryComboBox = new javax.swing.JComboBox<>();
jLabel3 = new javax.swing.JLabel();
jSeparator2 = new javax.swing.JSeparator();
productIDBox = new javax.swing.JTextField();
jSeparator5 = new javax.swing.JSeparator();
productPriceBox = new javax.swing.JTextField();
jSeparator6 = new javax.swing.JSeparator();
productQuantityBox = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
saveButton = new javax.swing.JButton();
doneButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
addButton = new javax.swing.JButton();
lblAdminAccess = new javax.swing.JLabel();
lblStatus = new javax.swing.JLabel();
jSeparator3 = new javax.swing.JSeparator();
jSeparator4 = new javax.swing.JSeparator();
lblItems = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setAlwaysOnTop(true);
setResizable(false);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jLabel1.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
jLabel1.setText("Product ID:");
jLabel1.setToolTipText("");
jLabel2.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
jLabel2.setText("Price:");
jLabel2.setToolTipText("");
jSeparator1.setBackground(new java.awt.Color(255, 51, 51));
jSeparator1.setForeground(new java.awt.Color(255, 0, 0));
jSeparator1.setToolTipText("");
jSeparator1.setName(""); // NOI18N
jSeparator1.setOpaque(true);
jSeparator1.setRequestFocusEnabled(false);
jSeparator1.setVerifyInputWhenFocusTarget(false);
productNameBox.setEditable(false);
productNameBox.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
productNameBox.setForeground(new java.awt.Color(153, 153, 153));
productNameBox.setHorizontalAlignment(javax.swing.JTextField.CENTER);
productNameBox.setToolTipText("");
productNameBox.setBorder(null);
productNameBox.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
productNameBox.setDisabledTextColor(new java.awt.Color(153, 153, 153));
productNameBox.setSelectionColor(new java.awt.Color(204, 204, 204));
categoryComboBox.setBackground(new java.awt.Color(255, 255, 255));
categoryComboBox.setEditable(true);
categoryComboBox.setForeground(new java.awt.Color(51, 51, 255));
categoryComboBox.setAutoscrolls(true);
categoryComboBox.setBorder(null);
categoryComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
categoryComboBoxItemStateChanged(evt);
}
});
jLabel3.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
jLabel3.setText("Quantity:");
jSeparator2.setBackground(new java.awt.Color(255, 51, 51));
jSeparator2.setForeground(new java.awt.Color(255, 0, 0));
jSeparator2.setToolTipText("");
jSeparator2.setName(""); // NOI18N
jSeparator2.setOpaque(true);
jSeparator2.setRequestFocusEnabled(false);
jSeparator2.setVerifyInputWhenFocusTarget(false);
productIDBox.setEditable(false);
productIDBox.setForeground(new java.awt.Color(153, 153, 153));
productIDBox.setToolTipText("");
productIDBox.setBorder(null);
jSeparator5.setBackground(new java.awt.Color(255, 51, 51));
jSeparator5.setForeground(new java.awt.Color(255, 0, 0));
jSeparator5.setToolTipText("");
jSeparator5.setName(""); // NOI18N
jSeparator5.setOpaque(true);
jSeparator5.setRequestFocusEnabled(false);
jSeparator5.setVerifyInputWhenFocusTarget(false);
productPriceBox.setEditable(false);
productPriceBox.setForeground(new java.awt.Color(153, 153, 153));
productPriceBox.setBorder(null);
jSeparator6.setBackground(new java.awt.Color(255, 51, 51));
jSeparator6.setForeground(new java.awt.Color(255, 0, 0));
jSeparator6.setToolTipText("");
jSeparator6.setName(""); // NOI18N
jSeparator6.setOpaque(true);
jSeparator6.setRequestFocusEnabled(false);
jSeparator6.setVerifyInputWhenFocusTarget(false);
productQuantityBox.setForeground(new java.awt.Color(0, 0, 255));
productQuantityBox.setBorder(null);
jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
jScrollPane1.setBorder(null);
jScrollPane1.setViewportBorder(null);
jScrollPane1.setOpaque(true);
jTable1.setBorder(null);
jTable1.setFont(new java.awt.Font("sansserif", 0, 11)); // NOI18N
jTable1.setForeground(new java.awt.Color(102, 102, 102));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"ID", "Product Name", "Price", "Qty"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Integer.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jTable1.setFillsViewportHeight(true);
jTable1.setGridColor(new java.awt.Color(255, 255, 255));
jTable1.setOpaque(false);
jTable1.setSelectionBackground(new java.awt.Color(204, 204, 204));
jTable1.setSelectionForeground(new java.awt.Color(0, 0, 0));
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
jTable1KeyReleased(evt);
}
});
jScrollPane1.setViewportView(jTable1);
saveButton.setText("Save");
saveButton.setEnabled(false);
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
doneButton.setText("Done");
doneButton.setToolTipText("");
doneButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
doneButtonActionPerformed(evt);
}
});
deleteButton.setText("Delete");
deleteButton.setToolTipText("");
deleteButton.setEnabled(false);
deleteButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteButtonActionPerformed(evt);
}
});
addButton.setText("Add");
addButton.setToolTipText("");
addButton.setEnabled(false);
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addButtonActionPerformed(evt);
}
});
lblAdminAccess.setFont(new java.awt.Font("sansserif", 0, 10)); // NOI18N
lblAdminAccess.setForeground(java.awt.Color.blue);
lblAdminAccess.setText("<html><u>Admin</u></html>");
lblAdminAccess.setToolTipText("<html> Turn Admin Mode: <font color=red>ON</font> </html> ");
lblAdminAccess.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
lblAdminAccess.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lblAdminAccessMouseClicked(evt);
}
});
lblStatus.setBackground(new java.awt.Color(255, 255, 255));
lblStatus.setFont(new java.awt.Font("sansserif", 0, 11)); // NOI18N
lblStatus.setForeground(new java.awt.Color(102, 102, 102));
lblStatus.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblStatus.setText("<html>Add or select a product category (Admin required to add).</html>");
lblStatus.setToolTipText("");
lblStatus.setBorder(null);
lblStatus.setOpaque(true);
jSeparator3.setBackground(new java.awt.Color(0, 153, 153));
jSeparator3.setToolTipText("");
jSeparator4.setBackground(new java.awt.Color(0, 153, 153));
jSeparator4.setToolTipText("");
lblItems.setFont(new java.awt.Font("sansserif", 0, 11)); // NOI18N
lblItems.setText("<html>Items: <font color=blue>0</font></html>");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE))
.addGap(32, 32, 32)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(productIDBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(productPriceBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(productQuantityBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(productNameBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(lblStatus)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblItems, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lblAdminAccess, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(categoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(saveButton)
.addGap(18, 18, 18)
.addComponent(addButton)
.addGap(18, 18, 18)
.addComponent(deleteButton)
.addGap(18, 18, 18)
.addComponent(doneButton)))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
.addComponent(jSeparator3)
.addComponent(jSeparator4)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(categoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblAdminAccess, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblItems, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(4, 4, 4)
.addComponent(productNameBox, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jLabel3))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(productIDBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(productPriceBox, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(productQuantityBox, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveButton)
.addComponent(doneButton)
.addComponent(deleteButton)
.addComponent(addButton))
.addGap(11, 11, 11)
.addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
setLocationRelativeTo(null);
}
由于代码太大,我在两篇文章中提供。只需在此代码正下方的下一篇文章中复制/粘贴代码即可。