aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Refresh the view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Refresh the view" Watch "Refresh the view" New topic
Author

Refresh the view

ravindra janapreddy
Ranch Hand

Joined: Jan 30, 2001
Posts: 84
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


SCEA, SCBCD, SCWCD, SCJD, SCJP
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
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

Joined: Jan 30, 2001
Posts: 84
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

Joined: Jan 30, 2001
Posts: 84
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

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
ravindra janapreddy
Ranch Hand

Joined: Jan 30, 2001
Posts: 84
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

Joined: Feb 05, 2001
Posts: 17259
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refresh the view