• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem getting GUI to work, and a lock() question

 
Lina Mahl
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have a JFrame with a button and a ScrollPane with my JTable (built with a TableModel) on. When I press my button I get the right information all the way up to my TableModel but I can�t get my GUI to update by it self. The right information is shown when I resize the frame for example.
I have tried to write this.pack() where I get the new information to my JFrame and I have an i_bookingPanel.pack() in the code where the action from the button is listened to but no....
Here is some of my code :
Here I listen to the button :
i_bookingPanel.addListenerToSearchButton(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String t_from = i_bookingPanel.getSelectedOrigin();
String t_to = i_bookingPanel.getSelectedDestination();
getFlightsFromTo(t_from, t_to);
i_bookingPanel.pack();
//i_bookingPanel.updateUI();
}
});
Here I get the information to the JFrame BookingPanel:
public void updateBookingPanel(HashSet a_flights) {
FlightTableModel t_flightModel = (FlightTableModel) i_flightTable.getModel();
t_flightModel.updateModel(a_flights);
//t_tablePane.updateUI();

//this.pack();
}

I build my BookingPanel in the constructor like this :
public BookingPanel(HashSet a_origin, HashSet a_dest, String[] a_columnNames) {
i_origin = a_origin;
i_dest = a_dest;
i_flightTable = makeJTable(a_columnNames);
this.getContentPane().add(makePanel());
this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
where makePanel() is a method that just sets al my components in place with GridLayout()
---
JScrollPane t_tablePane = new JScrollPane(i_flightTable);
---
t_mainPanel.add(t_tablePane, c);
And then I wonder about lock(int record)
Do you really need to know who locked the record? Is it not enough to know that it is locked?
I have a static hashtable and the key and the value is the record number.
Maybe it is obvious that the key should be who put a value in the hashtable.... but why?
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This doesn't look like Java code to me, -- I recommend that you follow Java Coding Conventions. Note the use of prefixes and underscores in variable names, -- there is no such thing in Java.
Regarding refreshing the data in JTable, look into the usage of methods fireTableStructureChanged(), fireTableCellUpdated(row, column), and fireTableDataChanged().
Eugene.
 
Lina Mahl
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips about the methods.
Yes I know that it is not a god way of naming variables..... I am working on it.
What about my lock question. Why is it importent to know WHO locked the record and not just that it IS locked?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the javadoc you've been given for Data.unlock() and take it from there.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic