Reputation: 159
I'm new to Java and the entire swing development. I'm working on a Window with three tabs and adding each component to those tabs. I started by adding a textfield to the 3rd tab, but it's taking up the entire tab. I'm sure if I add other components it will make room, but isn't there a way to make it so it doesn't initially take up the entire Tabbed Pane?
package literature.windows;
import java.awt.*;
import javax.swing.*;
public class MainWindow extends JFrame {
JPanel storiesPanel = new JPanel();
JPanel plotPanel = new JPanel();
JPanel charactersPanel = new JPanel();
JTextField addCharacterTextField = new JTextField("Enter Character's Name", 25);
public MainWindow() {
setSize(800, 600);
JTabbedPane tabs = new JTabbedPane();
tabs.addTab("Stories", storiesPanel);
tabs.addTab("Plot", plotPanel);
tabs.addTab("Characters", charactersPanel);
add(tabs);
tabs.setTabComponentAt(2, addCharacterTextField);
setVisible(true);
}
}
Upvotes: 2
Views: 218
Reputation: 159784
You are currently setting the entire tab component for that tab. Instead you need to add the JTextField
to the container/panel for that tab. Replace
tabs.setTabComponentAt(2, addCharacterTextField);
with
charactersPanel.add(addCharacterTextField);
Upvotes: 2