Java JTable set JButton and JTextField but output shows nothing - java

I have written the following code to make a JTable. I am practicing to edit value on row by setting JButton and JTextField but the output of JButton and JTextField is unseen.
public class quotingtable extends javax.swing.JFrame {
DefaultTableModel model;
JTable table;
String col[] = { "Symbol", "Name", "LastPrice" };
JButton button = new JButton("Set Value at 1, 1");
JTextField text = new JTextField(20);
JPanel panel = new JPanel();
public void start() {
model = new DefaultTableModel(col,50);
table = new JTable(model) {
#Override
public boolean isCellEditable(int arg0 ,int arg1) {
return false;
}
};
panel.add(table);
panel.add(text);
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String value = text.getText();
model.setValueAt(value, 1, 0);
}
});
JScrollPane pane = new JScrollPane(table);
table.setValueAt("VNM", 0, 0);
add(pane);
setSize(500, 400);
setLayout(new FlowLayout());
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[]) {
new quotingtable().start();
}
}

Related

Add Values from JTextFied to JTable

public class BillDetailsPanel implements ActionListener {
JPanel panel;
int flag = 0;
JLabel lItemName, lPrice, lQty, ltax, lDisPrice;
JTextField price, qty, tax, disPrice;
JComboBox<String> itemName;
String[] bookTitles = new String[] { "Effective Java", "Head First Java",
"Thinking in Java", "Java for Dummies" };
JButton addBtn
public BillDetailsPanel() {
panel = new JPanel();
panel.setPreferredSize(new Dimension(900, 50));
FlowLayout layout = new FlowLayout(FlowLayout.CENTER, 5, 15);
panel.setLayout(layout);
// panel.setBackground(Color.GREEN);
lItemName = new JLabel("Item Name");
lPrice = new JLabel("Price");
lQty = new JLabel("Quantity");
ltax = new JLabel("Tax");
lDisPrice = new JLabel("Discount Price");
itemName = new JComboBox<String>(bookTitles);
itemName.addActionListener(this);
price = new JTextField(8);
// price.setEditable(false);
qty = new JTextField(4);
tax = new JTextField(5);
// tax.setEditable(false);
disPrice = new JTextField(8);
addBtn = new JButton("Add");
addBtn.addActionListener(this);
panel.add(lItemName);
panel.add(itemName);
panel.add(lPrice);
panel.add(price);
panel.add(lQty);
panel.add(qty);
panel.add(ltax);
panel.add(tax);
panel.add(lDisPrice);
panel.add(disPrice);
panel.add(addBtn);
panel.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
BillTablePanel btp=new BillTablePanel();
String[] data=new String[5];
data[0]=(String) itemName.getSelectedItem();
data[1]=price.getText();
data[2]=qty.getText();
data[3]=tax.getText();
data[4]=qty.getText();
btp.model.addRow(data);
btp.model.addRow(data);
System.out.println(data+"dataaaaaaaaaaaa");
}
}
}
public class BillTablePanel implements ActionListener{
public JPanel panel;
public JTable table;
public JScrollPane scrollPane, scrollPane1;
public DefaultTableModel model;
public int a=10;
String[] data=new String[5];
public BillTablePanel () {
panel = new JPanel();
panel.setLayout(null);
model = new DefaultTableModel();
String columnNames[] = { "Item Name", "Actual Price", "Qty", "Tax",
"Price" };
table = new JTable();
model.setColumnIdentifiers(columnNames);
table.setModel(model);
table.setFocusable(false);
scrollPane = new JScrollPane(table);
scrollPane.setBounds(0, 0, 850, 100);
panel.add(scrollPane);
}
<br>
public class TestClassFrame {
JFrame f;
BillDetailsPanel bill = new BillDetailsPanel();
BillTablePanel billTablePanel = new BillTablePanel();
public TestClassFrame() {
f = new JFrame("Zeon Systems");
f.setLayout(null);
bill.panel.setBounds(0, 0, 900, 100);
f.add(bill.panel);
billTablePanel.panel.setBounds(0, 100, 900, 500);
f.add(billTablePanel.panel);
f.pack();
f.setSize(900, 550);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestClassFrame();
}
}
Problem with this code is The class Bill detais contain some text boxes and a button The BillTablepane class contain a Jtable I want to add the items from BillDetaisaPanel to the Jtable
On clicking the Jbutton which is not showing any error but the values are not inserting on it
The Full source is there Somebody please help me to find the logical error,
In your actionPerformed method, you're creating a new BillTablePanel object, at line (1), and then trying to add to the table model on line (2):
public void actionPerformed(ActionEvent e) {
BillTablePanel btp=new BillTablePanel(); // **** (1)
// ...
btp.model.addRow(data); // ***** (2)
But understand that that new BillTablePanel is just that, a completely new and distinct object, one completely unrelated to the one that is displayed. To change the state of the displayed data, you must call methods on the displayed BillTablePanel object, not on a new one that you create just for the actionPerformed method.
For example, here's a similar minimal program:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class TableExample extends JPanel {
private HoldsTable holdsTable = new HoldsTable();
private JTextField lastNameField = new JTextField(10);
private JTextField firstNameField = new JTextField(10);
public TableExample() {
JPanel fieldPanel = new JPanel();
fieldPanel.add(new JLabel("Last Name:"));
fieldPanel.add(lastNameField);
fieldPanel.add(new JLabel("First Name:"));
fieldPanel.add(firstNameField);
JPanel buttonPanel = new JPanel();
buttonPanel.add(new JButton(new AbstractAction("Your Action") {
#Override
public void actionPerformed(ActionEvent evt) {
HoldsTable ht = new HoldsTable(); // creates a new reference -- bad!
String lastName = lastNameField.getText();
String firstName = firstNameField.getText();
ht.addName(lastName, firstName);
}
}));
buttonPanel.add(new JButton(new AbstractAction("My Action") {
#Override
public void actionPerformed(ActionEvent evt) {
// HoldsTable ht = new HoldsTable();
String lastName = lastNameField.getText();
String firstName = firstNameField.getText();
// ht.addName(lastName, firstName);
holdsTable.addName(lastName, firstName); // use the ref to the displayed object
}
}));
setLayout(new BorderLayout());
add(holdsTable, BorderLayout.CENTER);
add(fieldPanel, BorderLayout.PAGE_START);
add(buttonPanel, BorderLayout.PAGE_END);
}
private static void createAndShowGui() {
TableExample mainPanel = new TableExample();
JFrame frame = new JFrame("TableExample");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}
class HoldsTable extends JPanel {
private static final String[] COL_NAMES = { "Last Name", "First Name" };
private DefaultTableModel model = new DefaultTableModel(COL_NAMES, 0);
private JTable table = new JTable(model);
public HoldsTable() {
setLayout(new BorderLayout());
add(new JScrollPane(table));
}
public void addName(String lastName, String firstName) {
String[] row = { lastName, firstName };
model.addRow(row);
}
}
Your program creates a new non-displayed object, and changes its properties, similar to this code in my program above:
#Override
public void actionPerformed(ActionEvent evt) {
HoldsTable ht = new HoldsTable(); // creates a new reference --
// bad!
String lastName = lastNameField.getText();
String firstName = firstNameField.getText();
ht.addName(lastName, firstName);
}
}));
But since the object whose state is being changed, here ht, but in your code its btp, is not the one that is displayed, nothing will show.
The correct way is shown in the other action:
#Override
public void actionPerformed(ActionEvent evt) {
// HoldsTable ht = new HoldsTable();
String lastName = lastNameField.getText();
String firstName = firstNameField.getText();
// ht.addName(lastName, firstName);
holdsTable.addName(lastName, firstName); // use the ref to the
// displayed object
}
I create a field of the GUI view that holds the JTable, here holdsTable and call a method on it. Since holdsTable is visible, changes in its state will be shown in the program (here the JTable).

How Would I have a button unique add a row to a JTable

I'm wondering how I would add a unique(changing one does't change all of them) row to a JTable with a JButton
final DefaultTableModel mod = new DefaultTableModel();
JTable t = new JTable(mod);
mod.addColumn{" "};
mod.addColumn{" "};
JButton b = new JButton
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//How would I make tf unique by producing a different variable every row if changed
final JTextField tf = new JTextField();
final Object[] ro = {"UNIQUE ROW", tf};
mode.addRow(ro);
}):
tf.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//s change to an other variable every row added
String s = tf.getText();
}):
You seem close, but you don't want to add JTextField's to a table row. Instead add the data it holds. For example:
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class UniqueRow extends JPanel {
public static final String[] COLS = {"Col 1", "Col 2"};
private DefaultTableModel model = new DefaultTableModel(COLS, 0);
private JTable table = new JTable(model);
private JTextField textField1 = new JTextField(10);
private JTextField textField2 = new JTextField(10);
public UniqueRow() {
add(new JScrollPane(table));
add(textField1);
add(textField2);
ButtonAction action = new ButtonAction("Add Data");
textField1.addActionListener(action);
textField2.addActionListener(action);
add(new JButton(action));
}
private class ButtonAction extends AbstractAction {
public ButtonAction(String name) {
super(name);
}
#Override
public void actionPerformed(ActionEvent e) {
// get text from JTextField
String text1 = textField1.getText();
String text2 = textField2.getText();
// create a data row with it. Can use Vector if desired
Object[] row = {text1, text2};
// and add row to JTable
model.addRow(row);
}
}
private static void createAndShowGui() {
UniqueRow mainPanel = new UniqueRow();
JFrame frame = new JFrame("UniqueRow");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}

Access variable in Action Listener from class

I've been trying for days to access some variables from a class above in an ActionListener, but I fail all the time :( What am I doing wrong? I hope you can help me folks.
public class FileFrameBetterStructured extends JFrame {
protected FileModel fileModel = new FileModel();
{
// Set Preferences
setSize(500, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Create table
FileModel fileModel = new FileModel();
JTable FileTable = new JTable(fileModel);
TableRowSorter<TableModel> TableRowSorter = new TableRowSorter<TableModel>(fileModel);
FileTable.setRowSorter(TableRowSorter);
FileTable.setColumnSelectionAllowed(true);
FileTable.setDefaultRenderer(Number.class, new BigRenderer(1000));
JScrollPane JScrollPane = new JScrollPane(FileTable);
getContentPane().add(JScrollPane, BorderLayout.CENTER);
// Create textfilter
JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("Filter");
panel.add(label, BorderLayout.WEST);
final JTextField filterText = new JTextField("");
panel.add(filterText, BorderLayout.CENTER);
add(panel, BorderLayout.NORTH);
JButton button = new JButton("Filter");
add(button, BorderLayout.SOUTH);
setSize(300, 250);
setVisible(true);
}
public static void main(String args[]) {
final FileFrameBetterStructured FileFrame = new FileFrameBetterStructured();
// Integrate ActionListener for textfilter
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
String text = filterText.getText();
if (text.length() == 0) {
TableRowSorter.setRowFilter(null);
} else {
TableRowSorter.setRowFilter(RowFilter.regexFilter(text));
}
}
});
}
}
In the ActionListener I want to access the variables: button, filterText and TableRowSorter. THANK YOU!
Add this to the top of your class:
protected static JButton button;
protected static JTextField filterText;
protected static TableRowSorter<TableModel> TableRowSorter;
Change your code as following
public class FileFrameBetterStructured extends JFrame {
static JButton button;
static JTextField filterText;
staitc TableRowSorter<TableModel> tableRowSorter;
protected FileModel fileModel = new FileModel();
FileFrameBetterStructured()
{
// Set Preferences
setSize(500, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Create table
FileModel fileModel = new FileModel();
JTable FileTable = new JTable(fileModel);
tableRowSorter = new TableRowSorter<TableModel>(fileModel);
FileTable.setRowSorter(TableRowSorter);
FileTable.setColumnSelectionAllowed(true);
FileTable.setDefaultRenderer(Number.class, new BigRenderer(1000));
JScrollPane JScrollPane = new JScrollPane(FileTable);
getContentPane().add(JScrollPane, BorderLayout.CENTER);
// Create textfilter
JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("Filter");
panel.add(label, BorderLayout.WEST);
filterText = new JTextField("");
panel.add(filterText, BorderLayout.CENTER);
add(panel, BorderLayout.NORTH);
button = new JButton("Filter");
add(button, BorderLayout.SOUTH);
setSize(300, 250);
setVisible(true);
}
public static void main(String args[]) {
final FileFrameBetterStructured FileFrame = new FileFrameBetterStructured();
// Integrate ActionListener for textfilter
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
String text = filterText.getText();
if (text.length() == 0) {
TableRowSorter.setRowFilter(null);
} else {
TableRowSorter.setRowFilter(RowFilter.regexFilter(text));
}
}
});
}
}
Hope it helps.

Table does not update when selecting combobox

My problem is that a JTable does not update when I select my combobox. The program I present below should delete all data (data = null;), when LA is selected. The table does not update.
public class minimumExample extends JFrame {
private JTabbedPane tabbedPane;
private FilteredTabPanel filteredTabPanel;
public void createTabBar() {
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
filteredTabPanel = new FilteredTabPanel();
tabbedPane.addTab("Test", filteredTabPanel.createLayout());
add(tabbedPane);
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}
private void makeLayout() {
setTitle("Test App");
setLayout(new BorderLayout());
setPreferredSize(new Dimension(1000, 500));
createTabBar();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public void start() {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
makeLayout();
}
});
}
public static void main(String[] args) throws IOException {
minimumExample ex = new minimumExample();
ex.start();
}
public class FilteredTabPanel extends JPanel {
private JPanel selectionArea;
private JLabel lCity;
private JComboBox cityBox;
private JTable filterTable;
String[] columnNames = {"Cities"};
String[][] data = {
{"NY"}, {"NY"}, {"NY"}, {"NY"}, {"LA"}, {"LA"},{"Columbia"},{"DC"},{"DC"},{"DC"},{"DC"},{"DC"},{"DC"}
};
private JScrollPane scrollPane;
public JPanel createLayout() {
JPanel panel = new JPanel(new GridLayout(0, 1));
//add panels to the layout
panel.add(addButtons());
panel.add(showTable());
repaint();
revalidate();
return panel;
}
public JPanel addButtons(){
selectionArea = new JPanel(new FlowLayout(FlowLayout.LEFT));
lCity = new JLabel("City");
String[] fillings = {"NY", "LA", "Columbia", "DC"};
cityBox = new JComboBox(fillings);
cityBox.addActionListener(new ActionListener() {
private String cityFilter;
#Override
public void actionPerformed(ActionEvent arg0) {
//2. get data
cityFilter = cityBox.getSelectedItem().toString();
if(cityFilter.equals("LA")) {
data = null;
}
showTable();
repaint();
}
});
selectionArea.add(lCity);
selectionArea.add(cityBox);
selectionArea.repaint();
return selectionArea;
}
private JScrollPane showTable() {
filterTable =new JTable(data, columnNames);
filterTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane = new JScrollPane(filterTable);
scrollPane.repaint();
scrollPane.validate();
return scrollPane;
}
}
}
As you can see the table does not update. Any recommendations what I am doing wrong?
Instead of creating new instance of you objects by calling showTable (which never get added to the screen in any way), which is just going to completely mess up your object references, try resetting the TableModel, for example...
if ("LA".equals(cityFilter)) {
filterTable.setModel(new DefaultTableModel(null, columnNames));
}
Take a closer look at How to Use Tables for more details

Trouble Updating AbstractTableModel from another Class

I'm trying to update a JTable that pulls in data from an ArrayList. I have two frames in my program. The first frame is a JTable (AbstractTableModel) that displays the contents of the ArrayList. I click the "New" button on that frame to bring up the second window, which lets me add to the aforementioned ArrayList. When I click my "Save" button, the second window closes and the first is supposed to refresh with the new row. I don't have any syntactical errors in my code, and it looks conceptually right. I think the first place to start troubleshooting would be in the NoteCntl class. I'm under the impression that getNoteTableUI() should update the view with the new data when it's called, but I'm stumped as to what's going on. I'm new to the concept of Model View Controller, but I'd like to follow that as closely as possible.
Here is the Controller class:
public class NoteCntl {
private NoteTableModel theNoteTableModel = new NoteTableModel();;
private NoteTableUI theNoteTableUI;
private NoteDetailUI theNoteDetailUI;
public NoteCntl(){
theNoteTableUI = new NoteTableUI(this);
}
public NoteTableModel getNoteTableModel(){
return theNoteTableModel;
}
public void getNoteDetailUI(Note theNote){
if (theNoteDetailUI == null || theNote == null){
theNoteDetailUI = new NoteDetailUI(this,theNote);
}
else{
theNoteDetailUI.setVisible(true);
}
}
public NoteTableUI getNoteTableUI(){
theNoteTableModel.fireTableDataChanged(); //why doesn't this do anything?
theNoteTableUI.setVisible(true);
return theNoteTableUI;
}
public void deleteNote(int noteToDelete){
theNoteTableModel.removeRow(noteToDelete);
}
}
The First UI (Table):
public class NoteTableUI extends JFrame{
NoteTableModel noteModel;
NoteCntl theNoteCntl;
JPanel buttonPanel;
JPanel tablePanel;
JTable theNoteTable;
JScrollPane theScrollPane;
JButton backButton;
JButton deleteButton;
JButton editButton;
JButton newButton;
public NoteTableUI(NoteCntl theParentNoteCntl){
theNoteCntl = theParentNoteCntl;
this.initComponents();
this.setSize(400, 500);
this.setLocationRelativeTo(null);
this.setTitle("NoteTableUI");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void initComponents(){
buttonPanel = new JPanel();
tablePanel = new JPanel();
backButton = new JButton("Back");
newButton = new JButton("New");
newButton.addActionListener(new newButtonListener());
editButton = new JButton("Edit");
deleteButton = new JButton("Delete");
deleteButton.addActionListener(new deleteButtonListener());
noteModel = theNoteCntl.getNoteTableModel();
theNoteTable = new JTable(theNoteCntl.getNoteTableModel());
theScrollPane = new JScrollPane(theNoteTable);
theNoteTable.setFillsViewportHeight(true);
tablePanel.add(theScrollPane);
buttonPanel.add(backButton);
buttonPanel.add(deleteButton);
buttonPanel.add(editButton);
buttonPanel.add(newButton);
this.getContentPane().add(buttonPanel, BorderLayout.NORTH);
this.getContentPane().add(tablePanel, BorderLayout.CENTER);
}
public class deleteButtonListener implements ActionListener{
public void actionPerformed(ActionEvent event){
int selectedRow = theNoteTable.getSelectedRow();
if (selectedRow == -1){
System.out.println("No row selected");
}
else{
noteModel.removeRow(selectedRow);
}
revalidate();
repaint();
}
}
public class newButtonListener implements ActionListener{
public void actionPerformed(ActionEvent event){
NoteTableUI.this.setVisible(false);
NoteTableUI.this.theNoteCntl.getNoteDetailUI(null);
/*
NoteDetailCntl theNoteDetailCntl = new NoteDetailCntl();
lastRow++;
long newRow = lastRow;
noteModel.addRow(newRow, 0, "", "");
revalidate();
repaint();
*/
}
}
The 2nd UI (Detail editor)
public class NoteDetailUI extends JFrame{
private final int FRAME_WIDTH = 700;
private final int FRAME_HEIGHT = 500;
private final int FIELD_WIDTH = 10;
JButton saveButton;
JButton backButton;
JTextField idField;
JTextField dateField;
JTextField nameField;
JTextField descriptionField;
JTextArea noteDetail;
JLabel idLabel;
JLabel dateLabel;
JLabel nameLabel;
JLabel descriptionLabel;
JPanel buttonPanel;
JPanel textFieldPanel;
JPanel textAreaPanel;
JPanel mainPanel;
NoteTableModel theNoteTableModel;
NoteDetailCntl theNoteDetailCntl;
NoteCntl theNoteCntl;
Note theCurrentNote;
public NoteDetailUI(){
this.initComponents();
this.setSize(FRAME_WIDTH,FRAME_HEIGHT);
this.setLocationRelativeTo(null);
this.setTitle("NoteDetailUI");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public NoteDetailUI(NoteCntl parentNoteCntl, Note theSelectedNote){
theNoteCntl = parentNoteCntl;
theCurrentNote = theSelectedNote;
this.initComponents();
this.setSize(400,500);
this.setLocationRelativeTo(null);
this.setTitle("Note");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void initComponents(){
saveButton = new JButton("Save");
saveButton.addActionListener(new saveButtonListener());
backButton = new JButton("Back");
backButton.addActionListener(new backButtonListener());
idField = new JTextField(FIELD_WIDTH);
theNoteTableModel = new NoteTableModel();
idField.setText("10");
idField.setEditable(false);
dateField = new JTextField(FIELD_WIDTH);
dateField.setText("20131108");
nameField = new JTextField(FIELD_WIDTH);
nameField.setText("Untitled");
descriptionField = new JTextField(FIELD_WIDTH);
descriptionField.setText("not described");
idLabel = new JLabel("ID");
dateLabel = new JLabel("Date");
nameLabel = new JLabel("Name");
descriptionLabel = new JLabel("Description");
noteDetail = new JTextArea(25,60);
buttonPanel = new JPanel();
textFieldPanel = new JPanel();
textAreaPanel = new JPanel();
mainPanel = new JPanel(new BorderLayout());
buttonPanel.add(backButton);
buttonPanel.add(saveButton);
textFieldPanel.add(idLabel);
textFieldPanel.add(idField);
textFieldPanel.add(dateLabel);
textFieldPanel.add(dateField);
textFieldPanel.add(nameLabel);
textFieldPanel.add(nameField);
textFieldPanel.add(descriptionLabel);
textFieldPanel.add(descriptionField);
textAreaPanel.add(noteDetail);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
mainPanel.add(textFieldPanel, BorderLayout.NORTH);
mainPanel.add(textAreaPanel, BorderLayout.CENTER);
add(mainPanel);
}
public ArrayList<String> getNoteDetails(){
ArrayList<String> newData = new ArrayList<String>();
newData.add(idField.getText());
newData.add(dateField.getText());
newData.add(nameField.getText());
newData.add(descriptionField.getText());
return newData;
}
public class saveButtonListener implements ActionListener{
public void actionPerformed(ActionEvent event){
/*
* Access the noteTableData array in NoteTableModel
* Add the newData fields in order
*/
if(theCurrentNote == null){
int newNoteNumber = Integer.parseInt(NoteDetailUI.this.idField.getText());
int newNoteDate = Integer.parseInt(NoteDetailUI.this.dateField.getText());
String newNoteName = NoteDetailUI.this.nameField.getText();
String newNoteDescription = NoteDetailUI.this.descriptionField.getText();
NoteDetailUI.this.theCurrentNote = new EssayNote(newNoteNumber,newNoteDate,newNoteName,newNoteDescription);
NoteDetailUI.this.setVisible(false);
NoteDetailUI.this.dispose();
NoteDetailUI.this.theNoteCntl.getNoteTableUI();
}
else{
//if it's a current Note
}
//Refresh the JTable
}
}
public class backButtonListener implements ActionListener{
public void actionPerformed(ActionEvent event){
}
}
Thanks for all the help. I can provide the other classes if you want to just run the program and see what's happening, but I suspect it's either a problem with the fireTableDataChanged() call in the controller class or a problem with updating the contents of the ArrayList in the SaveButtonListener.

Categories