-1
    textArea = new JTextArea(textString);
    JScrollPane text = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    text.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

そして、JScrollPaneテキストをJTabbedPaneに追加します。特別なことは何もありません。

ただし、タブを切り替えると、texfieldがウィンドウ全体を拡大およびサイズ変更します。

    JFrame frame = new JFrame();
    frame.setSize(600, 500);
    JPanel main = new JPanel();
    main.setLayout(new BorderLayout(0,0));
    main.setBorder(new EmptyBorder(10, 10, 10, 10) );
    textArea = new JTextArea(textString);
    JScrollPane text = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    text.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    JTabbedPane tabs = new JTabbedPane();
    tabs.add("Text lines", text);
    tabs.add("Another", new JPanel());
    main.add(new JLabel("test"), BorderLayout.NORTH);
    main.add(tabs, BorderLayout.SOUTH);
    frame.setContentPane(main);
    frame.pack();
4

1 に答える 1

2

あなたの例で私が見つけた問題は、テキスト領域に多くの行を入力して別のタブに切り替えると、タブ付きペインのサイズが大きくなることです。JTextAreaこれを修正するには、コンストラクターに表示するテキスト領域の行数を入力するだけです。たとえば、5行を表示するには:

textArea = new JTextArea(textString, 5, 0);

これで、タブ付きペインのサイズは変更されません。

于 2013-02-20T15:26:18.370 に答える