Page 1 of 3 123 LastLast
Results 1 to 20 of 43
  1. #1
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Exclamation How to reload JInternalFrame

    Greetings,

    I'm confused on how to reload my JInternalFrame upon updating a record in my database.

    My CUD (Create, Update, Delete) codes are functioning well. But after each function, the components won't update. Since I've tried using addItem() and removeItem() for my JComboBox but, I have ruined the order of the items.

    All I want to happen is after CUD of the JIF, the JIF will reload itself.

    The Source Code is placed in my previous thread.
    Click Here

    Thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

  3. #3
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    I'm despirate to find the solution.
    I have already triple posted this thread.

    Sorry for that.

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by chyrl View Post
    but, I have ruined the order of the items.

    for keeping the order in the list use the method insertItemAt(Object, index); you have to calculate the index in your code.

    JComboBox (Java 2 Platform SE v1.4.2), int)

    i wrote a small demoexample for you to demostrate how to cud. it has less logic in it but it demostrates cud works. so the initial combobox contains

    item1
    ite2
    item4

    pushing the creeate button, a item3 is inserted after ite2 (hard-coded, calculate the right place where to insert in your code). pushing update the ite2 is updated to item2 and finally pushing delete the item4 is deleted. push it only once, otherwise you will throw a ArrayIndexOutofBoundsException. here is the code for the jcombobox

    Java Code:
    package Employee;
    
    import java.awt.BorderLayout;
    import java.util.Vector;
    
    import javax.swing.DefaultComboBoxModel;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.WindowConstants;
    import javax.swing.event.MenuListener;
    
    public class ComboBoxExample extends JFrame {
    	private DefaultComboBoxModel myModel;
    	private JComboBox myComboBox;
    
    	public ComboBoxExample() {
    		// JComboBox
    		myComboBox = new JComboBox();
    		JPanel south = new JPanel();
    		
    		JButton create = new JButton("Create");
    		JButton update = new JButton("Update");
    		JButton delete = new JButton("Delete");
    		
    
    		
    		
    		south.add(create);
    		south.add(update);
    		south.add(delete);
    		
    		Vector<String> myItems = new Vector<String>();
    		myItems.add("item1");
    		myItems.add("ite2");
    		myItems.add("item4");
    		myModel = new DefaultComboBoxModel(myItems);
    		
    		myComboBox.setModel(myModel);
    		
    		MyActionListener listener = new MyActionListener(myModel);
    		create.addActionListener(listener);
    		update.addActionListener(listener);
    		delete.addActionListener(listener);
    		
    		// add ComboBox to Frame
    		
    		this.getContentPane().add(myComboBox, BorderLayout.NORTH);
    		this.getContentPane().add(south, BorderLayout.SOUTH);
    		this.pack();
    		this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    		this.setVisible(true);
    
    	}
    
    	public static void main(String[] args) {
    		new ComboBoxExample();
    	}
    }
    here is the code with the button listener

    Java Code:
    package Employee;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.DefaultComboBoxModel;
    
    public class MyActionListener implements ActionListener {
    
    	private DefaultComboBoxModel comboModel;
    
    	public MyActionListener(DefaultComboBoxModel newModel) {
    		this.comboModel = newModel;
    	}
    
    	public void actionPerformed(ActionEvent ev) {
    		String str = ev.getActionCommand();
    		// create new item
    		if (str.equals("Create")) {
    			this.comboModel.insertElementAt("item3", 2);
    			// update ite2 to item2
    		} else if (str.equals("Update")) {
    			this.comboModel.removeElementAt(1);
    			this.comboModel.insertElementAt("item2", 1);
    		} else if (str.equals("Delete")) {
    			// deletes item3
    			System.out.println("delete");
    			this.comboModel.removeElementAt(3);
    		}
    	}
    }

    i hope you understand the mecchano, otherwise ask. if you have a lot of inserts and updates it's perhaps easier to remove all items and rebuild the coplete list from scratch. but if you have simple changes you have only to change the item in the ComboBoxModel and the JComboBox is automatically rebuild.
    Last edited by j2me64; 04-01-2010 at 04:00 PM.

  5. #5
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Ok. But is there a way to refresh the JIF?
    Refreshing or reloading the JIF will be more appreciated than logically adjusting the lists of JComboBox.
    Last edited by chyrl; 04-02-2010 at 06:20 AM.

  6. #6
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    > Ok. But is there a way to refresh the JIF?

    I don't know what you explicitly mean by 'refresh'.
    you mentioned a refresh function in your other post - I didn't see
    a method of that name (although it was only a cursory glance).

    I can't run your code because you have db stuff that refers to a database I don't have.

    what you need to do, if you really want people to have a look at your problem is:
    1) post a compilable/runnable sample program with hard-coded data,
    the content of the data is irrelevant to your problem, stripping everything
    else unrelated to the problem - menus, or buttons/listeners that perform other functions etc
    2) explain the steps to require a refresh
    3)explain what your attempt at refresh actually does and what it is
    you're trying to achieve - be specific
    ('refresh' on its own means different things to different people)

  7. #7
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by chyrl View Post
    Ok. But is there a way to refresh the JIF?
    Refreshing or reloading the JIF will be more appreciated than logically adjusting the lists of JComboBox.

    if you really want to use internal frames then read this How to Use Internal Frames (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    here is a small excerpt from the above link

    You should consider carefully whether to base your program's GUI around frames or internal frames. Switching from internal frames to frames or vice versa is not necessarily a simple task. By experimenting with both frames and internal frames, you can get an idea of the tradeoffs involved in choosing one over the other.
    Last edited by j2me64; 04-02-2010 at 09:33 AM.

  8. #8
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    I agree with your consideration regarding Internal Frame.
    Actually, I do get confused programming the IF of my application. Yet it do have it's advantages when the application is runned.

    But I'm still having a hard time getting those IF refreshed after each CUD function is selected. For example if I have a refresh button in the IF together with several useful display components of a specific record, the IF would reload itself. In these manner, I could easily make the next IF dependent on it updated also.

  9. #9
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    j2me64:

    What I saw in your link was the fundamentals regarding JIF. But it help me in some other ways. Getting into the point. My question is, how could I be able to refresh the contents of my components(List of the JComboBox, DataModel of the JTable, Menu of the JMenuBar).

    Thanks.

  10. #10
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    I see we've just wasted out time trying to help you (won't happen again).

    Swing - How to reload JInternalFrame

    was it really that hard to break-down your code, and to explain exactly what you mean?

  11. #11
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by chyrl View Post
    But it help me in some other ways. Getting into the point. My question is, how could I be able to refresh the contents of my components(List of the JComboBox, DataModel of the JTable, Menu of the JMenuBar).

    what do you want to "refresh"? initially we were talking about a jcombobox and now you are talking about datamodel, jtable, menu and jmenubar. could you please be more precise?

  12. #12
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Actually to be general.
    Is there a way we could update all the components in just one call.
    I was asking if there's a way the JIF could be refreshed and not the component only?

  13. #13
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by chyrl View Post
    I was asking if there's a way the JIF could be refreshed and not the component only?

    i would say: no. because a jif can contain different component and each component must be refreshed in different ways. for your jtable read this How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) and then you will understand why.

  14. #14
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Quote Originally Posted by j2me64 View Post
    i would say: no. because a jif can contain different component and each component must be refreshed in different ways. for your jtable read this How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) and then you will understand why.
    Even though placing all components in a JPanel? You still need to refresh all the components?

  15. #15
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

  16. #16
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Problem is resolved thanks to repaint()
    Thanks to copeg of javaprogrammingforums
    I have resolve this problem.

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm glad that you have it solved, but next time, if you are going to cross-post, please post links to all of your cross-posts. Thank you for your cooperation.

  18. #18
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    I doubt using "repaint()" is the solution.

    It means your design is very strange, but based on the information given we can't provide a proper solution.

  19. #19
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    But I was wondering. What was the proper solution to this thread?
    What method am I suppose to use to the JComboBox for it to update or refresh its list?

    repaint(), revalidate(), updateUI() or ...?

  20. #20
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    You've been told (multiple times) we can't answer the question because we have no idea what you mean by "refresh" and you haven't posted your SSCCE showing what you are attempting to do.

Page 1 of 3 123 LastLast

Similar Threads

  1. How to reload form after saving
    By bikkerss in forum NetBeans
    Replies: 0
    Last Post: 02-14-2010, 07:10 PM
  2. Reload the page when any changes in the database
    By Kayal in forum Web Frameworks
    Replies: 0
    Last Post: 03-28-2009, 08:17 AM
  3. How to force Firefox to reload applet
    By JordashTalon in forum Java Applets
    Replies: 3
    Last Post: 02-20-2009, 12:19 PM
  4. reload form problem
    By porta325 in forum New To Java
    Replies: 2
    Last Post: 11-01-2007, 05:07 PM
  5. how to reload a jsp page
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-15-2007, 12:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •