| | |
How to position buttons/boxes in a JTabbed Pane?
![]() |
•
•
Join Date: Mar 2005
Posts: 13
Reputation:
Solved Threads: 0
Well the title prett much tells you what error I have XD...
so far....
[PHP]JLabel label1 = new JLabel( "AIRLINE RESERVATION", SwingConstants.CENTER );
JPanel panel1 = new JPanel();
panel1.add( label1 );
tabbedPane.addTab( "RESERVING", null, panel1, "FirstPanel");[/PHP]
then heres the problem....
[PHP]mealComboBox = new JComboBox( meals );
panel1.add( mealComboBox );
mealComboBox.setBounds( 200, 200, 170, 20 );
mealComboBox.setSelectedIndex( 0 );[/PHP]
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.
so far....
[PHP]JLabel label1 = new JLabel( "AIRLINE RESERVATION", SwingConstants.CENTER );
JPanel panel1 = new JPanel();
panel1.add( label1 );
tabbedPane.addTab( "RESERVING", null, panel1, "FirstPanel");[/PHP]
then heres the problem....
[PHP]mealComboBox = new JComboBox( meals );
panel1.add( mealComboBox );
mealComboBox.setBounds( 200, 200, 170, 20 );
mealComboBox.setSelectedIndex( 0 );[/PHP]
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 GridBagLayoutIf anyone can help, that would be greatly appreciated.
•
•
Join Date: Mar 2005
Posts: 13
Reputation:
Solved Threads: 0
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
[PHP]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");
}
}[/PHP]
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
[PHP]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");
}
}[/PHP]
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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:
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:
If I have time, I will try to make up an example applet that uses tabbedpanes, and maybe that will help you out.
Java Syntax (Toggle Plain Text)
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:
Java Syntax (Toggle Plain Text)
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.
•
•
Join Date: Mar 2005
Posts: 13
Reputation:
Solved Threads: 0
WEll i managed to fix it...
altho here's the main problem i was addressing...
see how it cramps up?
http://img179.echo.cx/img179/7200/error6xa.th.jpg
altho here's the main problem i was addressing...
see how it cramps up?
http://img179.echo.cx/img179/7200/error6xa.th.jpg
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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.
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.
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: java developers .... I need a good one :)
- Next Thread: Determining correct size of JDesktopPane
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






