import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
public class controlFrame extends JPanel {
JComponent[] panels;
JTextField textfield;
JTextArea designTextArea;
public controlFrame() {
super(new FlowLayout(FlowLayout.LEFT));
this.setSize(2200, 1100);
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setSize(800, 700);
ImageIcon icon=null;
panels = new JComponent[5];
panels[0] = makeTextPanel("Design");
tabbedPane.addTab("Design", icon, panels[0],
"Design");
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
textfield = new JTextField();
designTextArea = new JTextArea();
textfield.setSize(100, 40);
designTextArea.setSize(1000, 600);
panels[1] = makeTextPanel("Panel #1");
panels[1].add(textfield);
panels[0].add(designTextArea);
tabbedPane.addTab("tab 1", icon, panels[1],
null);
tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
panels[2] = makeTextPanel("Panel #2");
tabbedPane.addTab("tab 2", icon, panels[2],
"Still does nothing");
tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
panels[3] = makeTextPanel(
"tab 3");
panels[3].setPreferredSize(new Dimension(410, 50));
tabbedPane.addTab("tab 3", icon, panels[3],
"Does nothing at all");
tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
//Add the tabbed pane to this panel.
add(tabbedPane);
//The following line enables to use scrolling tabs.
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}
protected JComponent makeTextPanel(String text) {
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = controlFrame.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from
* the event dispatch thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("TabbedPaneDemo");
frame.setSize(1500, 1500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frame.add(new controlFrame(), 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();
}
});
}
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.