944,117 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 12222
  • Java RSS
May 29th, 2005
0

How to position buttons/boxes in a JTabbed Pane?

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
buggytoast is offline Offline
13 posts
since Mar 2005
May 29th, 2005
0

Re: How to position buttons/boxes in a JTabbed Pane?

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?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 29th, 2005
0

Re: How to position buttons/boxes in a JTabbed Pane?

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]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
buggytoast is offline Offline
13 posts
since Mar 2005
May 29th, 2005
0

Re: How to position buttons/boxes in a JTabbed Pane?

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:
Java Syntax (Toggle Plain Text)
  1. public void init()
  2. {
  3. //What would normaly be in the constructor goes here.
  4. }

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)
  1. Container content = getContentPane();
  2. fields.setLayout(new FlowLayout());
  3. setContentPane(content);
  4. 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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 29th, 2005
0

Re: How to position buttons/boxes in a JTabbed Pane?

Hi!
It is very suitable to use NetBeans temporary to see how to create GUI quickly, then you will not need it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
miri is offline Offline
10 posts
since Apr 2005
May 30th, 2005
0

Re: How to position buttons/boxes in a JTabbed Pane?

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
buggytoast is offline Offline
13 posts
since Mar 2005
May 31st, 2005
0

Re: How to position buttons/boxes in a JTabbed Pane?

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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: java developers .... I need a good one :)
Next Thread in Java Forum Timeline: Determining correct size of JDesktopPane





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC