Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refresh the view

 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JFrame and I have a panel which I have added to the frame. GridLayout(2,1) is set as the layout for the panel. I have added a menu bar as the first element. The menu bar has the following menu items initial flight information, search flight, book flight, exit , help etc. Now on clicking Initial Flight Information , I want to show up table as the second element in the Grid. The problem is that the table is not showing up. Please look at the partial code.
public class FBNAction extends JFrame {
panel = new JPanel(false);
container.add(panel, BorderLayout.NORTH);
panel.setLayout(new GridLayout(2,1));
JMenuBar menuBar = new JMenuBar();
panel.add(menuBar);
public void actionPerformed(ActionEvent ae) {
JTable table = new InitialFlightInformation().getData(mode, host, port);
System.out.println("FlightInformationAction JTable: " + table);
flightPanel = new JPanel();
flightPanel.setLayout(new BorderLayout());
flightPanel.add(table.getTableHeader(), BorderLayout.NORTH );
flightPanel.add(table);
panel.add(flightPanel);
}
How do I refresh/repaint the view to show the table ?
Thanks
Ravindra
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravindra,
Keep the layout simple and that means you don't want to hide and show components based on user actions. This is not a good design. Think about the layout below:
1) Add the JMenuBar to the JFrame
2) set the layout of the JFrame/ContentPane to BorderLayout
3) Add the search criteria panel to the NORTH
4) Add the JScrollPane which contains the JTable to the CENTER
5) Add the panel which can contain the seats to be reserved along with the "Book" JButton in the SOUTH.
I finally realized that one screen with one controller is good enough for this assignment. No need for even a JTabbedPane.
 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sai
Thanks for the idea. I shall redesign my GUI.
What do we need a menu bar for since the menu options i.e "flight information", "search criteria" and "book flight" show up all the time?
The only other menu options remaining are connection "local" or "remote" & "help" but these could also be provided for by a radiobutton option "local connection" or "remote connection" and a "help" button.
Ravindra
 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Observer Pattern
Observer Pattern
I am working on redesign the FBN application using a single screen.
I have the menu bar on top of the frame.
I have search criteria added to the North of the frame.
I have JTable added to the Center of the frame.
Finally, I have Book Button and the textfield for entering the # of
seats added to the South of Frame.
So the only view which changes is JTable data based on your selections
If I were to implement this using Observer pattern than Does that mean
that I should have menu bar class, search criteria class and book
flight class as the subject and JTable as the observer class?
Does this idea looks okay ?
Thanks
Ravindra
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using the Observer pattern, why don't you just add a JButton underneath your search criteria North section. Then when the user clicks the button the action would be to refresh your JTable with the new data.
Mark
 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark
Infact, There would be two buttons "Search" in North and "Book" in South and JTable would be refreshed when the user clicks on either button.
Ravindra
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So then what would you need an Observer for. I mean the Listener is actually like an Observer, if that's what you mean. But as far as having to build a class to be an Observer object, and code all that is uneccessary, if I am understanding your idea correctly.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic