I have created the following view extending the JPanel class, the objective of this view is to allow the user to perform 3 CRUD operations create,delete and modify on the entity "Attribute", this entity belong to an entity User or Client, so when the user wants to perform CRUD operations it has to specify if the operations will be performed on the User Attributes or Client Attributes
The view is divided in 2 parts:
The 1st one is for displaying Fixed Attributes from the User and Client entities, there's not need to perform CRUD operations on those.
The 2nd one is for performing the CRUD operations on the "Additional Attributes".
How can I improve my class? is there some way to create less JComboBoxes? How can I improve the look of the JScrollPane?
package view.attributePanes;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
@SuppressWarnings("serial")
public class PaneAttributeManagement extends JPanel {
/************ Strings[] **************/
private static String[] types = { "String", "Int", "Date", "Boolean" };
private static String[] entities = { "Users", "Clients" };
/************ JComboBoxes **************/
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComboBox boxAttributeTypes = new JComboBox(types);
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComboBox boxAttributeTypes1 = new JComboBox(types);
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComboBox boxEntities = new JComboBox(entities);
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComboBox boxEntities1 = new JComboBox(entities);
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComboBox boxEntities2 = new JComboBox(entities);
@SuppressWarnings({ "rawtypes" })
private JComboBox boxDeleteAttributesName = new JComboBox();
@SuppressWarnings({ "rawtypes" })
private JComboBox boxModifyAttributesName = new JComboBox();
/************ JTextFields **************/
JTextField addAttributeNameTxt = new JTextField(15);
JTextField addAttributeValueTxt = new JTextField(15);
JTextField modifyAttributeNameTxt = new JTextField(15);
JTextField modifyAttributeValueTxt = new JTextField(15);
/************ JButtons **************/
private JButton addNewAttributeBtn = new JButton("Add");
private JButton deleteAttributeBtn = new JButton("Delete");
private JButton modifyAttributeBtn = new JButton("Update");
/************ Main panes **************/
private JPanel mainPane;
private JScrollPane mainScrollPane;
public PaneAttributeManagement() {
mainPane = new JPanel();
mainPane.setLayout(new MigLayout("wrap 2", "[] 16 []"));
initComponents();
}
protected void initComponents() {
MigLayout layout = new MigLayout("wrap 2", "[grow][grow]", "[grow][grow][grow]");
setLayout(layout);
add(getMainScrollPane(), "cell 0 0");
mainPane.add(getFixedAttributesPanel(), "cell 0 0,grow");
mainPane.add(getAdditionalAttributePanel(), "cell 0 1 2 1,grow");
}
private JScrollPane getMainScrollPane() {
mainScrollPane = new JScrollPane(mainPane);
mainScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
mainScrollPane.setPreferredSize(new Dimension(470, 400));
return mainScrollPane;
}
private JPanel getFixedAttributesPanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Fixed Attributes"));
panel.setLayout(new MigLayout("wrap 2", "[] 16 []"));
panel.add(getFixedUserAttributesPanel());
panel.add(getFixedClientAttributesPanel());
return panel;
}
private JPanel getFixedUserAttributesPanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("User"));
panel.setLayout(new MigLayout("wrap 2", "[] 16 []"));
panel.add(new JLabel("1."), "right");
panel.add(new JLabel("User ID"));
panel.add(new JLabel("2."), "right");
panel.add(new JLabel("Name"));
panel.add(new JLabel("3."), "right");
panel.add(new JLabel("Surname"));
panel.add(new JLabel("4."), "right");
panel.add(new JLabel("Password"));
panel.add(new JLabel("5."), "right");
panel.add(new JLabel("Clients owned"));
return panel;
}
private JPanel getFixedClientAttributesPanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Client"));
panel.setLayout(new MigLayout("wrap 2", "[] 16 []"));
panel.add(new JLabel("1."), "right");
panel.add(new JLabel("Client ID"));
panel.add(new JLabel("2."), "right");
panel.add(new JLabel("Name"));
return panel;
}
private JPanel getAdditionalAttributePanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Additional Attributes"));
panel.setLayout(new MigLayout("wrap 1", "[] 16 []"));
panel.add(getAddAttributePanel());
panel.add(getModifyAttributePanel());
panel.add(getDeleteAttributePanel());
return panel;
}
private JPanel getAddAttributePanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Add Attribute"));
panel.setLayout(new MigLayout("wrap 2", "[]16[]", "[][][][][][]"));
panel.add(new JLabel("For:"));
panel.add(boxEntities);
panel.add(new JLabel("Name:"));
panel.add(addAttributeNameTxt);
panel.add(new JLabel("Type:"));
panel.add(boxAttributeTypes);
panel.add(new JLabel("Value:"));
panel.add(addAttributeValueTxt);
panel.add(addNewAttributeBtn, "cell 1 4, right");
return panel;
}
private JPanel getDeleteAttributePanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Delete Attributes"));
panel.setLayout(new MigLayout("wrap 2", "[]16[]", "[][][][][][]"));
panel.add(new JLabel("From:"));
panel.add(boxEntities1);
panel.add(new JLabel("Name:"));
panel.add(boxDeleteAttributesName);
panel.add(deleteAttributeBtn, "cell 2 3,right");
return panel;
}
private JPanel getModifyAttributePanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Modify Attributes"));
panel.setLayout(new MigLayout("wrap 2", "[]16[]", "[][][][][][]"));
panel.add(new JLabel("From:"));
panel.add(boxEntities2);
panel.add(new JLabel("Name:"));
panel.add(boxModifyAttributesName);
panel.add(new JLabel("New name:"));
panel.add(modifyAttributeNameTxt);
panel.add(new JLabel("New type:"));
panel.add(boxAttributeTypes1);
panel.add(new JLabel("New value:"));
panel.add(modifyAttributeValueTxt);
panel.add(modifyAttributeBtn, "cell 1 5, right");
return panel;
}
public String getAddAttributeNameTxt() {
return addAttributeNameTxt.getText();
}
public String getAddAttributeValueTxt() {
return addAttributeValueTxt.getText();
}
public String getModifyAttributeNameTxt() {
return modifyAttributeNameTxt.getText();
}
public String getModifyAttributeValueTxt() {
return modifyAttributeValueTxt.getText();
}
}