次の JTabbedPanes に問題があり、困惑しています。問題を短いデモ アプリケーションに切り分けました (オラクルのタブ付きペインのチュートリアルに基づく)。
package main.java;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class TabbedPaneDemo extends JPanel {
public static JTabbedPane topTabs = new JTabbedPane();
public TabbedPaneDemo() {
super(new BorderLayout());
topTabs.setPreferredSize(new Dimension(400, 200));
topTabs.add(makeReadoutPanel("\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15"));
add(topTabs);
}
private static JTabbedPane makeReadoutPanel(String text) {
// Create tabbed pane
JTabbedPane tabs = new JTabbedPane();
tabs.setName("Tabs");
// Create text field
JTextArea textArea = new JTextArea(text);
textArea.setEditable(false);
textArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
// Create first panel for text field
JPanel textPanel = new JPanel();
textPanel.setLayout(new BorderLayout());
textPanel.setName("Text Panel");
textPanel.add(textArea, BorderLayout.CENTER);
// Add text field panel to tabs
tabs.add(textPanel);
return tabs;
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("TabbedPaneDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frame.add(new TabbedPaneDemo(), BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}
これを実行すると、JTextArea はパネルに垂直に収まるのではなく、スクロール バーなしで切り取られます。textPanel の BorderLayout は、テキスト領域のサイズをタブにするべきではありませんか? これは、ネストされたタブでのみ発生します。単一レベルのタブのみを使用すると、テキスト領域が適切に収まります。