Ben Trafford
Posts: 7
Nickname: btrafford
Registered: May, 2002
|
|
Re: My tabbed panes won't appear. :^(
|
Posted: May 22, 2002 4:52 PM
|
|
> Please give us more details. You could also include > the code for the TestGUITabbedPanes class.
Okeydokey. This'll be longish, so bear with me.
TestGUIMainFrame The main frame of the application, where the tabbed panes should be loading. The place where I've assumed the tabbed panes should be loading is in this file, where I've written:
contentPane.add(mainScreen, BorderLayout.CENTER);
package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import test.TestGUITabbedPanes;
public class testGUIMainFrame extends JFrame {
JPanel contentPane;
// JDesktopPane contentPane;
/** Tabbed Pane */
TestGUITabbedPanes mainScreen = new TestGUITabbedPanes();
/** Menu Bar */
JMenuBar menuBar = new JMenuBar();
/** Tool Bar */
/** Look for more icons for toolbar */
JToolBar toolBar = new JToolBar();
JButton openFileButton = new JButton();
JButton closeFileButton = new JButton();
JButton helpButton = new JButton();
ImageIcon openFileButtonImage;
ImageIcon closeFileButtonImage;
ImageIcon helpButtonImage;
/** Status Bar */
JLabel statusBar = new JLabel();
/** Border Layout */
BorderLayout borderLayout = new BorderLayout();
/** Menus and Menu Items */
/** File Menu */
JMenu menuFile = new JMenu();
JMenuItem menuFileNew = new JMenuItem();
JMenuItem menuFileOpen = new JMenuItem();
JMenuItem menuFileClose = new JMenuItem();
JMenuItem menuFileSave = new JMenuItem();
JMenuItem menuFilePrint = new JMenuItem();
JMenuItem menuFileExit = new JMenuItem();
/** Edit Menu */
JMenu menuEdit = new JMenu();
JMenuItem menuEditUndo = new JMenuItem();
JMenuItem menuEditCut = new JMenuItem();
JMenuItem menuEditCopy = new JMenuItem();
JMenuItem menuEditPaste = new JMenuItem();
/** Options Menu */
JMenu menuOptions = new JMenu();
JMenuItem menuOptionsSkins = new JMenuItem();
JMenuItem menuOptionsWebUpdate = new JMenuItem();
JMenuItem menuOptionsPreferences = new JMenuItem();
/** Help Menu */
JMenu menuHelp = new JMenu();
JMenuItem menuHelpIndex = new JMenuItem();
JMenuItem menuHelpContents = new JMenuItem();
JMenuItem menuHelpAbout = new JMenuItem();
/** Construct the frame */
public TestGUIMainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/** Component initialization */
private void jbInit() throws Exception {
/** Images */
openFileButtonImage = new ImageIcon(test.TestGUIMainFrame.class.getResource("images/openFile.gif"));
closeFileButtonImage = new ImageIcon(test.TestGUIMainFrame.class.getResource("images/closeFile.gif"));
helpButtonImage = new ImageIcon(test.TestGUIMainFrame.class.getResource("images/help.gif"));
setIconImage(Toolkit.getDefaultToolkit().createImage(test.TestGUIMainFrame.class.getResource("images/herosmall.jpg")));
/** Initialize Pane */
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout);
this.setSize(new Dimension(400, 300));
this.setTitle("TestGUI");
statusBar.setText("TestGUI Alpha");
contentPane.add(toolBar, BorderLayout.NORTH);
contentPane.add(mainScreen, BorderLayout.CENTER);
contentPane.add(statusBar, BorderLayout.SOUTH);
/** Initialize Menus with Action Listeners */
/** File Menu */
menuFile.setText("File");
menuFileNew.setText("New");
menuFileOpen.setText("Open");
menuFileClose.setText("Close");
menuFileSave.setText("Save");
menuFilePrint.setText("Print");
menuFile.addSeparator();
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
menuFileExit_actionPerformed(e);
}
});
/** Edit Menu */
menuEdit.setText("Edit");
menuEditUndo.setText("Undo");
menuEditCut.setText("Cut");
menuEditCopy.setText("Copy");
menuEditPaste.setText("Paste");
/** Options Menu */
menuOptions.setText("Options");
menuOptionsSkins.setText("Skins");
menuOptionsWebUpdate.setText("Web Update");
menuOptionsPreferences.setText("Preferences");
/** Help Menu */
menuHelp.setText("Help");
menuHelpIndex.setText("Index");
menuHelpContents.setText("Contents");
menuHelpAbout.setText("About");
menuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
menuHelpAbout_actionPerformed(e);
}
});
/** End Initializing Menus */
/** Icons */
openFileButton.setIcon(openFileButtonImage);
openFileButton.setToolTipText("Open File");
closeFileButton.setIcon(closeFileButtonImage);
closeFileButton.setToolTipText("Close And Exit");
helpButton.setIcon(helpButtonImage);
helpButton.setToolTipText("Help");
toolBar.add(openFileButton);
toolBar.add(closeFileButton);
toolBar.add(helpButton);
/** Add Menu Items */
/** File Menu */
menuFile.add(menuFileNew);
menuFile.add(menuFileOpen);
menuFile.add(menuFileClose);
menuFile.add(menuFileSave);
menuFile.add(menuFilePrint);
menuFile.add(menuFileExit);
/** Edit Menu */
menuEdit.add(menuEditUndo);
menuEdit.add(menuEditCut);
menuEdit.add(menuEditCopy);
menuEdit.add(menuEditPaste);
/** Options Menu */
menuOptions.add(menuOptionsSkins);
menuOptions.add(menuOptionsWebUpdate);
menuOptions.add(menuOptionsPreferences);
/** Help Menu */
menuHelp.add(menuHelpIndex);
menuHelp.add(menuHelpContents);
menuHelp.add(menuHelpAbout);
/** Menu Bar */
menuBar.add(menuFile);
menuBar.add(menuEdit);
menuBar.add(menuWizards);
menuBar.add(menuTools);
menuBar.add(menuOptions);
menuBar.add(menuHelp);
this.setJMenuBar(menuBar);
/** Quick Keys */
menuFileNew.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.CTRL_MASK));
menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_O, ActionEvent.CTRL_MASK));
menuFileSave.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_S, ActionEvent.CTRL_MASK));
menuFilePrint.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_P, ActionEvent.CTRL_MASK));
menuFileExit.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_X, ActionEvent.ALT_MASK));
menuEditUndo.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
menuEditCut.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_X, ActionEvent.CTRL_MASK));
menuEditCopy.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_C, ActionEvent.CTRL_MASK));
menuEditPaste.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_V, ActionEvent.CTRL_MASK));
menuHelpContents.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_H, ActionEvent.CTRL_MASK));
}
/** Actions */
/** File | New action performed */
/** File | Open action performed */
/** File | Close action performed */
/** File | Save action performed */
/** File | Print action performed */
/** File | Exit action performed */
public void menuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/** Help | About action performed */
/** Overridden so we can exit when window is closed */
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
menuFileExit_actionPerformed(null);
}
}
}
TestGUITabbedPanes This is the class where the tabbed panes are setup.
package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TestGUITabbedPanes extends JPanel
{
JTabbedPane tabbedPane;
JPanel panel1;
JPanel panel2;
JPanel panel3;
public TestGUITabbedPanes()
{
// Create the tab pages
createPage1();
createPage2();
createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Test Tab 1", panel1);
tabbedPane.addTab("Test Tab 2", panel2);
tabbedPane.addTab("Test Tab 3", panel3);
}
public void createPage1()
{
panel1 = new JPanel();
panel1.setLayout(null);
JLabel label1 = new JLabel("Username:");
label1.setBounds( 10, 15, 150, 20 );
panel1.add(label1);
JTextField field = new JTextField();
field.setBounds(10, 35, 150, 20);
panel1.add(field);
JLabel label2 = new JLabel( "Password:" );
label2.setBounds( 10, 60, 150, 20 );
panel1.add( label2 );
JPasswordField fieldPass = new JPasswordField();
fieldPass.setBounds( 10, 80, 150, 20 );
panel1.add( fieldPass );
}
public void createPage2()
{
panel2 = new JPanel();
panel2.setLayout( new BorderLayout() );
panel2.add( new JButton( "North" ), BorderLayout.NORTH );
panel2.add( new JButton( "South" ), BorderLayout.SOUTH );
panel2.add( new JButton( "East" ), BorderLayout.EAST );
panel2.add( new JButton( "West" ), BorderLayout.WEST );
panel2.add( new JButton( "Center" ), BorderLayout.CENTER );
}
public void createPage3()
{
panel3 = new JPanel();
panel3.setLayout( new GridLayout( 3, 2 ) );
panel3.add( new JLabel( "Field 1:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 2:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 3:" ) );
panel3.add( new TextArea() );
}
}
Phew! Sorry for the spam, but there it is. Any help, again, would be greatly appreciated. I'm sure I'm just being stupid.
|
|