2013-05-29 49 views
0

正如問題所述,我試圖保存我嵌入到JTabbedPane中的JTextArea的內容。我知道如何保存JTextArea的內容,但我無法弄清楚如何在JTabbedPane中嵌入內容時保存它的內容。保存JTextArea嵌入到JTabbedPane的內容

問題是,我正在動態添加選項卡,就像在Gedit中完成一樣。我不知道如何保存新生成的標籤。

這裏是我的代碼:

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); 

} 

} 

回答

0

下打破你的問題分成各個步驟:

  1. 獲取當前選定的選項卡
  2. 獲取文本顯示的選項卡
  3. 保存在使用文本區域的寫入(...)方法的文本區域的內容