As the question states, I'm trying to save the contents of JTextArea which I've embedded into a JTabbedPane. I know how to save the contents of a JTextArea, but I can't figure out how to save its contents when it's embedded in a JTabbedPane.
The problem is that I'm adding the tab dynamically, like it's done in Gedit. I don't know how to save the newly generated tab.
Here's my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class tabbed
{
public static void main(String[] arhs)
{
JFrame frame = new JFrame("");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTabbedPane tab = new JTabbedPane();
JButton butadd = new JButton("Add");
JButton butcheck = new JButton("Save");
JPanel north = new JPanel();
JPanel south = new JPanel();
north.add(butadd);
south.add(butcheck);
ActionListener listenadd = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tab.add("Untitled",new JTextArea());
}
};
butadd.addActionListener(listenadd);
frame.add(north, BorderLayout.NORTH);
frame.add(tab);
frame.add(south, BorderLayout.SOUTH);
frame.setSize(450,450);
frame.setVisible(true);
}
}
Break your problem down into individual steps:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.