How to position buttons/boxes in a JTabbed Pane?

Reply

Join Date: Mar 2005
Posts: 13
Reputation: buggytoast is an unknown quantity at this point 
Solved Threads: 0
buggytoast buggytoast is offline Offline
Newbie Poster

How to position buttons/boxes in a JTabbed Pane?

 
0
  #1
May 29th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

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

 
0
  #2
May 29th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 13
Reputation: buggytoast is an unknown quantity at this point 
Solved Threads: 0
buggytoast buggytoast is offline Offline
Newbie Poster

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

 
0
  #3
May 29th, 2005
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]
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

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

 
0
  #4
May 29th, 2005
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:
  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 10
Reputation: miri is an unknown quantity at this point 
Solved Threads: 0
miri miri is offline Offline
Newbie Poster

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

 
0
  #5
May 29th, 2005
Hi!
It is very suitable to use NetBeans temporary to see how to create GUI quickly, then you will not need it.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 13
Reputation: buggytoast is an unknown quantity at this point 
Solved Threads: 0
buggytoast buggytoast is offline Offline
Newbie Poster

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

 
0
  #6
May 30th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

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

 
0
  #7
May 31st, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC