Results 1 to 20 of 43
Thread: How to reload JInternalFrame
- 04-01-2010, 03:52 AM #1
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
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.
- 04-01-2010, 07:21 AM #2
Why the double post?
How to refresh my JInternalFrame upon CUD
db
- 04-01-2010, 07:28 AM #3
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
I'm despirate to find the solution.
I have already triple posted this thread.
Sorry for that.
- 04-01-2010, 02:56 PM #4
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
here is the code with the button listenerJava 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(); } }
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 03:00 PM.
- 04-02-2010, 05:03 AM #5
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
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 05:20 AM.
- 04-02-2010, 07:59 AM #6
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
> 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)
- 04-02-2010, 08:29 AM #7
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 08:33 AM.
- 04-02-2010, 09:01 AM #8
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
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.
- 04-04-2010, 03:21 PM #9
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
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.
- 04-05-2010, 08:33 AM #10
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
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?
- 04-05-2010, 08:35 AM #11
- 04-05-2010, 04:18 PM #12
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
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?
- 04-05-2010, 07:14 PM #13
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.
- 04-06-2010, 05:30 AM #14
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
- 04-06-2010, 07:11 AM #15
Another cross post:
How to reload JInternalFrame - Java Programming Forums
db
- 04-06-2010, 12:58 PM #16
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
Problem is resolved thanks to repaint()
Thanks to copeg of javaprogrammingforums
I have resolve this problem.
-
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.
- 04-06-2010, 04:59 PM #18
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
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.
- 04-07-2010, 06:29 AM #19
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
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 ...?
- 04-07-2010, 06:34 AM #20
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Similar Threads
-
How to reload form after saving
By bikkerss in forum NetBeansReplies: 0Last Post: 02-14-2010, 06:10 PM -
Reload the page when any changes in the database
By Kayal in forum Web FrameworksReplies: 0Last Post: 03-28-2009, 07:17 AM -
How to force Firefox to reload applet
By JordashTalon in forum Java AppletsReplies: 3Last Post: 02-20-2009, 11:19 AM -
reload form problem
By porta325 in forum New To JavaReplies: 2Last Post: 11-01-2007, 04:07 PM -
how to reload a jsp page
By Heather in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-14-2007, 11:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks