I’m re doing a specific application, just a basic text editor and I remember I had tabs and a JMenu so if you went File –> New it would add or ‘Open’ another tab on the JTabbedPane. But this time it’s not doing it for me, could someone help? Here is how im doing it:
newFile.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
tabs.addTab("new file", text);
}
}
);
So when it’s clicked it should add another tab but it’s not for some reason…
If it matters there is a default tab open at the beginning and when you click new it wipes out the old one.
Thanks for any help! (Please ask if you need anymore explanation)
Here I uploaded my code here since the editor here kept saying I the way I was putting it in wasnt formatted correctly:
http://nardcake.com/java
There is 2 files there, one initializes it and the other is everything else
thanks!
try:
I have removed these two lines (those two are anyhow called in the end by addTab() method), and rewritten your init.java like this:
It works now. To quote myself:
EDIT:
All the GUI related code must be executed on the EDT. You can test if some part of your code is run by EDT like this:
If it prints true you are safe to do a GUI update (e.g. call methods on Swing components instances) – like in 1 or anywhere in EBLFWE class. However 2 will print false – it is because the thread that runs your program is not EDT.
When calling SwingUtilities.invokeLater() you are actually placing that code to be executed (at some appropriate time the EDT sees fit) in the Event dispatch thread.
EDT does the actual painting, and a lot of other tasks, so when you call GUI update code from another thread you can mess up the order and get unwanted visual apperance.