When I compile my project from IntelliJ there isn't any problem and my program runs smoothly, but when I try to compile it from the terminal with javac, the warning "Note: Victor/presentation/TableControllerMenu.java uses unchecked or unsafe operations." pops out, and when I try to execute it I get the error "Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.". I guess IntelliJ is not writing the initialization code of the object contentPane in the file and that's causing javac to freak out. I have tried to change the option File -> Settings -> GUI Designer -> Generate GUI into from "Binary source file" to "Java source code", but that just produced a lot more errors when compiling...
That's the code of the GUI, tell me if some more code is needed:
package Victor.presentation;
import Victor.domain.TCPresPersInterface;
import Victor.persistence.TCRow;
import Victor.persistence.TCUtilities;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
public class TableControllerMenu extends JFrame {
static private TCPresPersInterface persInterface;
private DefaultTableModel newModel;
private JTableHeader newHeader;
private JPanel mainPanel;
private JButton rowEditorButton;
private JButton columnCastingButton;
private JButton manageTablesButton;
private JButton columnEditorButton;
private JButton basicUtilitiesButton;
private JButton fileHandlerButton;
private JButton goBackButton;
private JPanel ManageTablesPanel;
private JPanel BasicUtilitiesPanel;
private JPanel RowEditorPanel;
private JPanel ColumnEditorPanel;
private JPanel ColumnCastingPanel;
private JPanel FileHandlerPanel;
private JButton duplicateCurrentTableButton;
private JButton renameCurrentTableButton;
private JTextField duplicateTableNameField;
private JTextField renameTableField;
private JButton renameColumnButton;
private JButton modifyItemButton;
private JButton clearTableButton;
private JTextField newColumnNameField;
private JTextField newItemField;
private JTextField selectedColumnRenameField;
private JTextField newItemColumnField;
private JTextField newItemRowField;
private JCheckBox clearTableConfirmationBox;
private JButton addEmptyRowButton;
private JButton duplicateRowButton;
private JButton deleteRowButton;
private JTextField emptyRowField;
private JTextField rowDuplicateField;
private JTextField positionDuplicatedField;
private JTextField rowDeleteFIeld;
private JButton addEmptyColumnButton;
private JButton duplicateColumnButton;
private JButton moveColumnButton;
private JButton negateBinaryColumnButton;
private JButton deleteColumnButton;
private JTextField addEmptyColPosFIeld;
private JTextField duplicateColColFIeld;
private JTextField duplicatedColPosField;
private JTextField moveColColFIeld;
private JTextField moveColPosFIeld;
private JTextField negateColColField;
private JTextField deleteColColField;
private JButton columnToNumericalButton;
private JButton columnToBinaryButton;
private JButton columnToBinaryByButton;
private JButton columnToCategoricalButton;
private JTextField colNumericalColField;
private JTextField colBinaryColField;
private JComboBox colBinItemsBox;
private JTextField colBinIntervalDivField;
private JComboBox colBinaryIntervalLowerBox;
private JComboBox colBinEqualBox;
private JTextField colCategoricalField;
private JComboBox selItemsValBox;
private JTextField colBinIntervalColField;
private JButton importCSVButton;
private JButton exportCSVButton;
private JTextField importPathField;
private JTextField pathExportField;
private JTextField separatorImportField;
private JComboBox headerImportField;
private JComboBox dataTypeImportBox;
private JTextField separatorExportField;
private JComboBox headerExportField;
private JComboBox dataTypeExportField;
private JTabbedPane currentMenuTab;
private JPanel currentMenuPane;
private JTabbedPane tabbedPane1;
private JPanel currentTablePanel;
private JTable currentTable;
private JComboBox newColumnDType;
private JLabel manageTablesErrorLog;
private JLabel currentTableText;
private JLabel tableSizeText;
private JLabel errorLogText;
private JLabel tableHeaderText;
private JLabel tableTypesText;
private JTextField separatorColBinFIeld;
private JTextField itemsColBinFIeld;
private JButton deleteItemBoxButton;
private TableControllerMenu(String appName) {
super(appName);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(mainPanel);
this.pack();
persInterface = TCPresPersInterface.getInstance();
actualize(true);
// DUPLICATE CURRENT TABLE BUTTON
duplicateCurrentTableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String newName = duplicateTableNameField.getText();
String error = persInterface.duplicateTable(newName);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
duplicateTableNameField.setText("");
}
}
});
// RENAME CURRENT TABLE BUTTON
renameCurrentTableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String newName = renameTableField.getText();
String error = persInterface.renameTable(newName);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(false);
renameTableField.setText("");
}
}
});
// IMPORT TABLE FROM FILE BUTTON
importCSVButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String path = importPathField.getText();
String separator = separatorImportField.getText();
String header = (String) headerImportField.getSelectedItem();
String type = (String) dataTypeImportBox.getSelectedItem();
String error = persInterface.fileHandling(false, path, separator, header, type);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
importPathField.setText("");
separatorImportField.setText("");
headerImportField.setSelectedIndex(0);
dataTypeImportBox.setSelectedIndex(0);
}
}
});
// EXPORT TABLE TO FIELD BUTTON
exportCSVButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String path = pathExportField.getText();
String separator = separatorExportField.getText();
String header = (String) headerExportField.getSelectedItem();
String type = (String) dataTypeExportField.getSelectedItem();
String error = persInterface.fileHandling(true, path, separator, header, type);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(false);
pathExportField.setText("");
separatorExportField.setText("");
headerExportField.setSelectedIndex(0);
dataTypeExportField.setSelectedIndex(0);
}
}
});
// RENAME COLUMN BUTTON
renameColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String newName = newColumnNameField.getText();
String col = selectedColumnRenameField.getText();
String error = persInterface.renameColumn(newName, col);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
newColumnNameField.setText("");
selectedColumnRenameField.setText("");
}
}
});
// MODIFY ITEM BUTTON
modifyItemButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String value = newItemField.getText();
String row = newItemRowField.getText();
String col = newItemColumnField.getText();
String error = persInterface.modifyItem(value, row, col);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
newItemField.setText("");
newItemRowField.setText("");
newItemColumnField.setText("");
}
}
});
// CLEAR TABLE BUTTON
clearTableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (clearTableConfirmationBox.isSelected()) {
String error = persInterface.clearTable();
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
clearTableConfirmationBox.setSelected(false);
}
} else
errorLogText.setText("ERROR: the 'are you sure' box must be marked in order to clear the table");
}
});
// ADD EMPTY ROW BUTTON
addEmptyRowButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String position = emptyRowField.getText();
String error = persInterface.addEmptyRow(position);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
emptyRowField.setText("");
}
}
});
// DUPLICATE ROW BUTTON
duplicateRowButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String row = rowDuplicateField.getText();
String pos = positionDuplicatedField.getText();
String error = persInterface.duplicateRow(row, pos);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
rowDuplicateField.setText("");
positionDuplicatedField.setText("");
}
}
});
// DELETE ROW BUTTON
deleteRowButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String row = rowDeleteFIeld.getText();
String error = persInterface.deleteRow(row);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
rowDeleteFIeld.setText("");
}
}
});
// ADD EMPTY COLUMN BUTTON
addEmptyColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String pos = addEmptyColPosFIeld.getText();
String dtype = (String) newColumnDType.getSelectedItem();
String error = persInterface.addEmptyColumn(pos, dtype);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
addEmptyColPosFIeld.setText("");
newColumnDType.setSelectedIndex(0);
}
}
});
// DUPLICATE COLUMN BUTTON
duplicateColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String col = duplicateColColFIeld.getText();
String pos = duplicatedColPosField.getText();
String error = persInterface.duplicateCol(col, pos);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
duplicateColColFIeld.setText("");
duplicatedColPosField.setText("");
}
}
});
// MOVE COLUMN BUTTON
moveColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String col = moveColColFIeld.getText();
String pos = moveColPosFIeld.getText();
String error = persInterface.moveCol(col, pos);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
moveColColFIeld.setText("");
moveColPosFIeld.setText("");
}
}
});
// NEGATE BINARY COLUMN BUTTON
negateBinaryColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String col = negateColColField.getText();
String error = persInterface.negateBinaryCol(col);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
negateColColField.setText("");
}
}
});
// DELETE COLUMN BUTTON
deleteColumnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String col = deleteColColField.getText();
String error = persInterface.deleteCol(col);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
deleteColColField.setText("");
}
}
});
// COLUMN TO NUMERICAL BUTTON
columnToNumericalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String col = colNumericalColField.getText();
String error = persInterface.colToNumeric(col);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
colNumericalColField.setText("");
}
}
});
// COLUMN TO BINARY BUTTON
columnToBinaryButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String items = itemsColBinFIeld.getText();
String separator = separatorColBinFIeld.getText();
String castTo = (String) selItemsValBox.getSelectedItem();
String col = colBinaryColField.getText();
String error = persInterface.colToBinary(col, items, separator, castTo);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
selItemsValBox.setSelectedIndex(0);
colBinaryColField.setText("");
itemsColBinFIeld.setText("");
separatorColBinFIeld.setText("");
}
}
});
// COL TO BINARY INTERVAL
columnToBinaryByButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String div = colBinIntervalDivField.getText();
String lower = (String) colBinaryIntervalLowerBox.getSelectedItem();
String equal = (String) colBinEqualBox.getSelectedItem();
String col = colBinIntervalColField.getText();
String error = persInterface.colToBinaryInterval(col, div, lower, equal);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
colBinIntervalDivField.setText("");
colBinaryIntervalLowerBox.setSelectedIndex(0);
colBinEqualBox.setSelectedIndex(0);
colBinIntervalColField.setText("");
}
}
});
// COLUMN TO CATEGORICAL BUTTON
columnToCategoricalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
String col = colCategoricalField.getText();
String error = persInterface.colToCategory(col);
if (!error.equals(""))
errorLogText.setText("ERROR: " + error);
else {
errorLogText.setText("");
actualize(true);
colCategoricalField.setText("");
}
}
});
}
private void actualize(Boolean reloadTable) {
String current = persInterface.getCurrentTable();
currentTableText.setText("Current table: " + current);
tableSizeText.setText("Size: " + persInterface.getSizeText());
errorLogText.setText("");
if (reloadTable) {
try {
//TCUtilities.print(current);
int n_cols = TCUtilities.getNCols(current);
int n_rows = TCUtilities.getNRows(current);
String header_string = Arrays.toString(TCUtilities.getHeader(current).toArray());
header_string = header_string.replace("[", "");
header_string = header_string.replace("]", "");
String type_string = "";
for (int i = 0; i < n_cols; i++) {
if (i != 0) type_string += ", ";
type_string += TCUtilities.getColType(current, i).toString();
}
tableHeaderText.setText("Header: " + header_string);
tableTypesText.setText("Column types: " + type_string);
newModel = new DefaultTableModel(n_cols, n_rows + 2);
for (int i = 0; i < TCUtilities.getNRows(current); i++) {
newModel.insertRow(i, (Object[]) TCRow.getRow(current, i).toArray(new Object[n_cols]));
}
currentTable.setModel(newModel);
newHeader = new JTableHeader();
} catch (Exception e) {
System.out.println("ERROR IN ACTUALIZE: " + e.getMessage());
}
}
}
public static String execute(String currentTable) {
TCPresPersInterface.setCurrentTable(currentTable);
JFrame frame = new TableControllerMenu("Table Managing and Editing");
frame.setVisible(true);
return TCPresPersInterface.getCurrentTable();
}
public static void setCurrentTable(String currentTable) {
persInterface.setCurrentTable(currentTable);
}
public static Boolean hasCurrentTable() {
return persInterface.hasCurrentTable();
}
}
I finally solved it. What I did is: File -> Settings -> Editor -> GUI Designer and change the option "Generate GUI into:" from Binary class files to Java source code and changing in all the panes the 'Layout manager' option grom Grid Layout Manager (IntelliJ) to GridBagLayout (I suppose this works because is not an internal IntelliJ format), and it compiled.