Adding my own object to a Container...not working.
Okay, so this is my first post. Hello all! :D
I am writing a program for my dad to use at his cabinet making business. The program is being designed to create the dimensions for cabinet doors. My problem is, on the second display I have a JComboBox I want to show up. I created a new class to use to instantiate this box, and now it doesn't show up because I can't add it to my Container. I tried changing my ComboBox.java to extend JComboBox so it would be considered a Component, buuuut that didn't work so well for me. So instead, the ComboBox.java is considered an object I made and not a component, therefore my container will not allow me to add it so it shows up. Any ideas and/or solutions would be wonderful! Thank You!
PS. My ComboBox class compiles with no errors, the only error on my GUI class is that I can't add my own object.
here is the portion of my GUI that I am trying to add the box to:
Code :
/*** ComboBox Being Created ***/
public ComboBox createComboBox()
{
boxPanel = new JPanel();
boxDoorType = new ComboBox( createDoubleDoorDisplay(),
createSingleDoorOptions(),
createDoubleDoorOptions() );
boxPanel.add( boxDoorType );
c.add( boxPanel );
return boxDoorType;
}
And here is my ComboBox class:
Code :
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
import java.awt.Dimension.*;
public class ComboBox implements ItemListener
{
/*** Class Variables ***/
private String[] boxOptions = new String[ 3 ];
private JPanel[] boxDisplays = new JPanel[ 3 ];
private JComboBox cmbxDoorType;
private JPanel createDoubleDoorDisplay;
private JPanel createSingleDoorOptions;
private JPanel createDoubleDoorOptions;
/*** Constructor ***/
public ComboBox( JPanel pCreateDoubleDoorDisplay,
JPanel pCreateSingleDoorOptions,
JPanel pCreateDoubleDoorOptions,
String pBoxOption1,
String pBoxOption2,
String pBoxOption3)
{
createDoubleDoorDisplay = pCreateDoubleDoorDisplay;
createDoubleDoorDisplay.setVisible( false );
createSingleDoorOptions = pCreateSingleDoorOptions;
createSingleDoorOptions.setVisible( false );
createDoubleDoorOptions = pCreateDoubleDoorOptions;
createDoubleDoorOptions.setVisible( false );
}
/*** Accessors ***/
public String[] getBoxOptions()
{
return boxOptions;
}
public JPanel[] getBoxDisplays()
{
return boxDisplays;
}
/*** Mutators/Transformers ***/
public void setBoxOptions( String pBoxOptions, int pInt )
{
boxOptions[ pInt ] = pBoxOptions;
}
public void setBoxDisplays( JPanel pBoxDisplays, int pInt )
{
boxDisplays[ pInt ] = pBoxDisplays;
pBoxDisplays.setVisible( true );
}
public JComboBox createComboBox( String pBoxOption1,
String pBoxOption2,
String pBoxOption3 )
{
setBoxOptions( pBoxOption1, 0 );
setBoxOptions( pBoxOption2, 1 );
setBoxOptions( pBoxOption3, 2 );
cmbxDoorType = new JComboBox( boxOptions ); // JComboBox is Deprecated.
cmbxDoorType.addItemListener( this );
return cmbxDoorType;
}
public void itemStateChanged( ItemEvent e )
{
if ( e.getStateChange() == ItemEvent.SELECTED )
{
if ( boxDisplays[ cmbxDoorType.getSelectedIndex() ].equals( 0 ) )
{
setBoxDisplays( createDoubleDoorDisplay, 0 );
createDoubleDoorDisplay.setVisible( true );
}
else if ( boxDisplays[ cmbxDoorType.getSelectedIndex() ].equals( 1 ) )
{
setBoxDisplays( createSingleDoorOptions, 1 );
createSingleDoorOptions.setVisible( true );
}
else if ( boxDisplays[ cmbxDoorType.getSelectedIndex() ].equals( 2 ) )
{
setBoxDisplays( createDoubleDoorOptions, 2 );
createDoubleDoorOptions.setVisible( true );
}
}
}
}
Re: Adding my own object to a Container...not working.