Well the title prett much tells you what error I have XD...

so far....

JLabel label1 = new JLabel( "AIRLINE RESERVATION", SwingConstants.CENTER );
        JPanel panel1 = new JPanel();
	panel1.add( label1 );
        tabbedPane.addTab( "RESERVING", null, panel1, "FirstPanel");

then heres the problem....

mealComboBox = new JComboBox( meals );
        panel1.add( mealComboBox );
        mealComboBox.setBounds( 200, 200, 170, 20 );
        mealComboBox.setSelectedIndex( 0 );

the setbounds is definetely wrong...use that for container :( I keep tryin but it doesn't seem to work...and i'm not experienced enough to use GridBagLayout

If anyone can help, that would be greatly appreciated.

Recommended Answers

All 6 Replies

You could add a layout manager to the JPanel, but it's probably not going to be as pretty as you want.

Do you mind posting a screenshot of what it's doing?

Heres my program...so far.
The applet is not initiliazing now and I have no idea why...
It's unfinished so yeah alot of the stuff is unused so far XD
SOrry i couldn't put up a pic

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.border.*;

public class ReservationProgram extends JFrame {
    
    private JLabel phoneLabel, firstLabel, lastLabel, dateLabel, mealLabel;
    private JTextField phoneTextField, firstTextField, lastTextField, dateTextField, mealTextField;
    private JComboBox mealComboBox, classComboBox, destinationComboBox;
    private String destinations[] = { "Select Destination", "Mae Hong Son", "Chiang Mai"};
    private String meals[] = { "Select Meal", "Normal", "Vegetarian" }; 
    private String classes[] = { "Select Class", "Normal", "Business" };
    private CustomerInfo List[];
    
    private JButton addButton, saveButton, loadButton, deleteButton, searchButton,
            changeNameButton, changeLNameButton, changeMealButton, changeSeatButton,
            editButton, cancelButton, newButton;
    
    // Gui Setup
    public ReservationProgram()
    {
        super( "Airlines Reservation");
        // create JTabbed Pane
        
        JTabbedPane tabbedPane = new JTabbedPane();

        // set up panel1 and add to JTabbedPane
        JLabel label1 = new JLabel( "AIRLINE RESERVATION", SwingConstants.CENTER );
        JPanel panel1 = new JPanel();
	panel1.add( label1 );
        tabbedPane.addTab( "RESERVING", null, panel1, "FirstPanel");
        
        mealComboBox = new JComboBox( meals );
        panel1.add( mealComboBox );
        mealComboBox.setBounds( 200, 200, 170, 20 );
        mealComboBox.setSelectedIndex( 0 );
        
        classComboBox = new JComboBox( classes );
        panel1.add( classComboBox );
        classComboBox.setBounds( 200, 200, 170, 20 );
        classComboBox.setSelectedIndex( 0 );
        
        destinationComboBox = new JComboBox( destinations );
        panel1.add( destinationComboBox );
        destinationComboBox.setBounds( 200, 200, 170, 20 );
        destinationComboBox.setSelectedIndex( 0 );
        
        firstLabel = new JLabel ( "First Name:" );
        panel1.add( firstLabel );
        firstLabel.setBounds( 50, 20, 100, 20 );
        
        firstTextField = new JTextField();
        panel1.add( firstTextField );
        firstTextField.setBounds( 120, 50,  100, 20);
        
        
        JLabel label2 = new JLabel( "panel two", SwingConstants.CENTER );
        JPanel panel2 = new JPanel();
	panel2.add( label2 );
        tabbedPane.addTab( "EDITING / DELETING", null, panel2, "SecondPanel");
        
        JLabel label3 = new JLabel( "panel three", SwingConstants.CENTER );
        JPanel panel3 = new JPanel();
	panel3.add( label3 );
        tabbedPane.addTab( "DISPLAY ARRANGEMENTS", null, panel3, "ThirdPanel");
        
        JLabel label4 = new JLabel( "panel four", SwingConstants.CENTER );
        JPanel panel4 = new JPanel();
	panel4.add( label4 );
        tabbedPane.addTab( "SEAT DISPLAY", null, panel4, "FourthPanel");
        
        JLabel label5 = new JLabel( "panel five", SwingConstants.CENTER );
        JPanel panel5 = new JPanel();
	panel5.add( label5 );
        tabbedPane.addTab( "BOARDING PASS", null, panel5, "FivePanel");
        
    }
        
    
}

There's a few problems with what you have. First of all it's not an applet! You extended JFrame, instead of JApplet. Next, applets don't have constructors or main methods. Instead of a main method they have the init() method. EX:

public void init()
{
  //What would normaly be in the constructor goes here.
}

Then your not adding the components to anything. You need a container that will hold the JPanels, TabbedPanes, and that kind of stuff. After that you must set it visible. In the init method you'll finish with something that looks like this:

Container content = getContentPane();
		fields.setLayout(new FlowLayout());
		setContentPane(content);
		setVisible(true)

If I have time, I will try to make up an example applet that uses tabbedpanes, and maybe that will help you out.

Hi!
It is very suitable to use NetBeans temporary to see how to create GUI quickly, then you will not need it.

It depends how you want to position them. You can use nested JPanels with layoutmanagers attatched to them, or if you just want some of the labels and stuff spread out, you can always add white spaces to them when constructing.

JLabel lbl = new JLabel("Label ");

like that but I wouldn't recommend it unless you are desperate.

I would also increase the size of that JFrame. That could be one reason why it's so cramped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.