Updated selected row of JTable from another class












0















I have a JTable on my main form that I'd like to allow to edit specific rows. I created a edit button from a pop-up menu that creates a new window that reflects the data from the row selected in a new JFrame window with an Update button that I would like to update the selected row in my table on the main form.



I have a custom TableModel which accepts a a complex type SaleItem, I have a method that will create a new SaleItem based off the data manipulated on the pop-up frame, but am unsure how I can send it back to update the selected row of my table.



Here is where I create the new frame:



private void jMenuEditActionPerformed(java.awt.event.ActionEvent evt) {
int index = jTable1.getSelectedRow();
SalesTableModel model = (SalesTableModel) jTable1.getModel();
NewJFrameEdit frame = new NewJFrameEdit(model.getRow(index));
frame.setVisible(true);
}


Here is the new window relevant methods:



public NewJFrameEdit(SaleItem editableItem) {
initComponents();

jDateChooserInstallDateUpdater.setDate(editableItem.postDate);
jTextFieldWorkOrderUpdater.setText(editableItem.workOrderNumber);
chkUpdateTv.setSelected(editableItem.newTv);
chkUpdateInt.setSelected(editableItem.newInt);
chkUpdatePh.setSelected(editableItem.newPh);
editedItem = editableItem;
}

private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}

public SaleItem getUpdatedItem(){
return new SaleItem(
editedItem.dateAdded,
jDateChooserInstallDateUpdater.getDate(),
editedItem.agentName,
jTextFieldWorkOrderUpdater.getText(),
chkUpdateInt.isSelected(),
chkUpdateTv.isSelected(),
chkUpdatePh.isSelected(),
false
);
}


Solved!
I had to pass my table model when I called my NewJFrameEdit constructor!










share|improve this question

























  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 18 '18 at 5:47
















0















I have a JTable on my main form that I'd like to allow to edit specific rows. I created a edit button from a pop-up menu that creates a new window that reflects the data from the row selected in a new JFrame window with an Update button that I would like to update the selected row in my table on the main form.



I have a custom TableModel which accepts a a complex type SaleItem, I have a method that will create a new SaleItem based off the data manipulated on the pop-up frame, but am unsure how I can send it back to update the selected row of my table.



Here is where I create the new frame:



private void jMenuEditActionPerformed(java.awt.event.ActionEvent evt) {
int index = jTable1.getSelectedRow();
SalesTableModel model = (SalesTableModel) jTable1.getModel();
NewJFrameEdit frame = new NewJFrameEdit(model.getRow(index));
frame.setVisible(true);
}


Here is the new window relevant methods:



public NewJFrameEdit(SaleItem editableItem) {
initComponents();

jDateChooserInstallDateUpdater.setDate(editableItem.postDate);
jTextFieldWorkOrderUpdater.setText(editableItem.workOrderNumber);
chkUpdateTv.setSelected(editableItem.newTv);
chkUpdateInt.setSelected(editableItem.newInt);
chkUpdatePh.setSelected(editableItem.newPh);
editedItem = editableItem;
}

private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}

public SaleItem getUpdatedItem(){
return new SaleItem(
editedItem.dateAdded,
jDateChooserInstallDateUpdater.getDate(),
editedItem.agentName,
jTextFieldWorkOrderUpdater.getText(),
chkUpdateInt.isSelected(),
chkUpdateTv.isSelected(),
chkUpdatePh.isSelected(),
false
);
}


Solved!
I had to pass my table model when I called my NewJFrameEdit constructor!










share|improve this question

























  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 18 '18 at 5:47














0












0








0








I have a JTable on my main form that I'd like to allow to edit specific rows. I created a edit button from a pop-up menu that creates a new window that reflects the data from the row selected in a new JFrame window with an Update button that I would like to update the selected row in my table on the main form.



I have a custom TableModel which accepts a a complex type SaleItem, I have a method that will create a new SaleItem based off the data manipulated on the pop-up frame, but am unsure how I can send it back to update the selected row of my table.



Here is where I create the new frame:



private void jMenuEditActionPerformed(java.awt.event.ActionEvent evt) {
int index = jTable1.getSelectedRow();
SalesTableModel model = (SalesTableModel) jTable1.getModel();
NewJFrameEdit frame = new NewJFrameEdit(model.getRow(index));
frame.setVisible(true);
}


Here is the new window relevant methods:



public NewJFrameEdit(SaleItem editableItem) {
initComponents();

jDateChooserInstallDateUpdater.setDate(editableItem.postDate);
jTextFieldWorkOrderUpdater.setText(editableItem.workOrderNumber);
chkUpdateTv.setSelected(editableItem.newTv);
chkUpdateInt.setSelected(editableItem.newInt);
chkUpdatePh.setSelected(editableItem.newPh);
editedItem = editableItem;
}

private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}

public SaleItem getUpdatedItem(){
return new SaleItem(
editedItem.dateAdded,
jDateChooserInstallDateUpdater.getDate(),
editedItem.agentName,
jTextFieldWorkOrderUpdater.getText(),
chkUpdateInt.isSelected(),
chkUpdateTv.isSelected(),
chkUpdatePh.isSelected(),
false
);
}


Solved!
I had to pass my table model when I called my NewJFrameEdit constructor!










share|improve this question
















I have a JTable on my main form that I'd like to allow to edit specific rows. I created a edit button from a pop-up menu that creates a new window that reflects the data from the row selected in a new JFrame window with an Update button that I would like to update the selected row in my table on the main form.



I have a custom TableModel which accepts a a complex type SaleItem, I have a method that will create a new SaleItem based off the data manipulated on the pop-up frame, but am unsure how I can send it back to update the selected row of my table.



Here is where I create the new frame:



private void jMenuEditActionPerformed(java.awt.event.ActionEvent evt) {
int index = jTable1.getSelectedRow();
SalesTableModel model = (SalesTableModel) jTable1.getModel();
NewJFrameEdit frame = new NewJFrameEdit(model.getRow(index));
frame.setVisible(true);
}


Here is the new window relevant methods:



public NewJFrameEdit(SaleItem editableItem) {
initComponents();

jDateChooserInstallDateUpdater.setDate(editableItem.postDate);
jTextFieldWorkOrderUpdater.setText(editableItem.workOrderNumber);
chkUpdateTv.setSelected(editableItem.newTv);
chkUpdateInt.setSelected(editableItem.newInt);
chkUpdatePh.setSelected(editableItem.newPh);
editedItem = editableItem;
}

private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}

public SaleItem getUpdatedItem(){
return new SaleItem(
editedItem.dateAdded,
jDateChooserInstallDateUpdater.getDate(),
editedItem.agentName,
jTextFieldWorkOrderUpdater.getText(),
chkUpdateInt.isSelected(),
chkUpdateTv.isSelected(),
chkUpdatePh.isSelected(),
false
);
}


Solved!
I had to pass my table model when I called my NewJFrameEdit constructor!







java swing class jtable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 22:01







Derek Bailey

















asked Nov 18 '18 at 5:45









Derek BaileyDerek Bailey

11




11













  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 18 '18 at 5:47



















  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 18 '18 at 5:47

















1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) See The Use of Multiple JFrames, Good/Bad Practice?

– Andrew Thompson
Nov 18 '18 at 5:47





1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) See The Use of Multiple JFrames, Good/Bad Practice?

– Andrew Thompson
Nov 18 '18 at 5:47












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358247%2fupdated-selected-row-of-jtable-from-another-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358247%2fupdated-selected-row-of-jtable-from-another-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)