1

I have two separate components, one is a class that extends JTable, the other is a class that extends JPanel (contains a form).

Both are displayed on the same view when that application is run, when I click on a row on the table, I expect the textfileds on the form to be updated but nothing happens I use observer (the form class is the listener) pattern to send the clicked row to the class/ panel containing the form fields to be updated, the values are received but the textfields are not updated.

The code below is in the form class and it updates the form fields, the form class is added as a listener in the table class, the method below is fired when a table row is clicked

public void onTableRowClick(CollectedParcelEvent e)
{
     JOptionPane.showMessageDialog(null,"test", "test", 1);

    txtCost.setText(Double.toString(e.getSource().getCost()));
    txtCustomerName.setText(e.getSource().getCustomer().getName());


    txtCost.repaint();
    txtCost.revalidate();

}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Neo
  • 717
  • 2
  • 11
  • 26
  • Put your complete code so that your problem could be understood better.. – Vishal K Mar 28 '13 at 17:44
  • Have you run in debug to see if the textField is really updated ? To see if it's coming from the UI – DessDess Mar 28 '13 at 17:45
  • Are you sure that method is being fired when a table row is clicked? You shouldn't have to repaint and revalidate as well. Setting the text should work just fine, perhaps that's the reason. – adchilds Mar 28 '13 at 17:45
  • Nothing happens or it just "freezes" ? – joey rohan Mar 28 '13 at 17:47
  • for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, just about a.m. issue – mKorbel Mar 28 '13 at 17:56

2 Answers2

1
public void onTableRowClick(CollectedParcelEvent e)
{
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            //JOptionPane.showMessageDialog(null,"test", "test", 1);
            txtCost.setText(Double.toString(e.getSource().getCost()));
            txtCustomerName.setText(e.getSource().getCustomer().getName());
        }
    });
}

Events are handled on the single event thread. There the GUI is not responsive for other events, and one should postpone doing such things later with invokeLater.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • //THIS IS TABLE CLASS public class TableParcelsList extends JTable { // THIS IS THE TABLE CLASS, RENDERS TABLE STRCTURE, DOES NOT DEFINE EVENT HANDLERS } – Neo Mar 28 '13 at 18:52
0

I don't understand why are you calling revalidate(); as its just tells the layout manager to reset based on the newly added or removed component list.

See this link for more answers about using revalidate(); and also this one

And perhaps, repaint(); should be enough for the required change.

So check your method to see if it really gets fired or not.

Community
  • 1
  • 1
Abubakkar
  • 15,488
  • 8
  • 55
  • 83
  • @ykel like this we can never solve your problem.Show us some more code.I can give an example which will use same stmts. which you have and will work without any problem.So, it's better if we can get some more info. – joey rohan Mar 29 '13 at 05:31