JComboBox Visibility on JFrame

Hi All,
I am developing an Applet application. The application requires a new window to be displayed on button click, so I used JFrame in developing the new window which is popped up. In the new window I need a JComboBox. I added the JComboBox along with the other components to the frame. All the other components added are visible but the JComboBox is not visible. Then I added a border for the ComboBox then the border is visble but the box is not visible. When I click on the area represented by the Border I am able to view the list of the elements that are added to the Combobox. When I select one of the components from the list the selected component is not displayed on the box. I tried using setBackground(Color.white) but I am not able to see the ComboBox and only a white rectagular box is visible. I am not able to see atleast the arrow mark on the ComboBox which is used to display the list of items added to the ComboBox.
Any help is greatly appreciated,
Regards,
Ranjith.

First of all thanks for your reply
The code is
public class PacketConfigurationPanel extends JPanel implements ActionListener{
//Defining variables
JFrame frame;
JComboBox patternComboBox;
MyTextField typeField;
Font commonFont;
int positionX, positionY, frameWidth, frameHeight;
int dlWidth, dlHeight, prWidth, prHeight;
//Constructor
public PacketConfigurationPanel() {
//Initialization
frame = new JFrame("Packet Configuration Dialog");
frameWidth = 500;
frameHeight = 500;
frame.setSize(frameWidth, frameHeight);
Container contentPane = frame.getContentPane();
contentPane.setLayout(null);
frame.setVisible(true);
commonFont = new Font("Dialog", Font.PLAIN, 12);
positionX = 15;
positionY = 15;
positionY += 17;
String[] element = {"Blah Blah", "Blah Blah"};
patternComboBox = new JComboBox(element);
patternComboBox.setFont(commonFont);
patternComboBox.setVisible(true);
patternComboBox.setEditable(true);
//patternComboBox.setForeground(Color.black);
//patternComboBox.setSelectedIndex(0);
patternComboBox.setBounds(positionX, positionY, 100, 20);
//patternComboBox.setOpaque(true);
contentPane.add(patternComboBox);
//contentPane.setBackground(Color.blue);
I removed the code which is used to add other components to the frame and included the code which is used to add the ComboBox. This class is called by another class which is used to develop the applet.
Waiting for your reply,
Ranjith.

Similar Messages

  • Code to display  hindi fonts in JComboBox in a JFrame

    Hi friends,
    My mail id is [email protected] and please give response as soon as possible.
    My problem:In java,my Jcombobox contents is displaying only english fonts like arial or verdena or timesnewroman
    My requirement:
    I want source code or logic to display the contents in a JComboBox with hindi fonts or any other international language.
    That means,by choosing the language font my Jcombobox contents should be changed to that corresponding language dynamically.
    Note: I have used java internationalization with locale classes,but it is not working. please help me

    You might try giving the file a ".txt" extension. Then drag it on top of your Safari icon in the dock, which should open it with Safari. Then, under "View", select a Japanese "Text Encoding". My guess is that this is Shift-JIS.
    I am assuming you have not removed Japanese fonts from your system.

  • JComboBox Visibility Problem

    Hi, I am trying to use JComboBox for selecting you race and gender in a RPG I am making, but The contents of the JComboBox will not appear in the small version (before you click the little arrow) unless you first move one of the JSliders... Could some one help me figure this out?
    //I call the class with this
         newGamePanel = new newGamePanel();
         newGamePanel.setLayout(null);
         newGamePanel.setBounds(0, 0, programWidth, programHeight);
         newGamePanel.setBackground(Color.black);
         frame.getContentPane().add(newGamePanel);
         newGamePanel.setVisible(true);
         newGamePanel.setUpAlpha();
         newGamePanel.repaint();
    //and here is my class where it all takes place...  The relivent method is setUpAlpha()
    public class newGamePanel extends JPanel//Sets up and grabs the information for the character creation
    implements ActionListener, ChangeListener
         JButton newGameOK;
         JTextField newGameName;
         JComboBox newGameRace, newGameGender;
         JSlider newGameSTR, newGameAGI, newGameVIT, newGameDEX, newGameINT, newGameLUK;
         JLabel nGameName, nGameRace, nGameGender, nGameSTR, nGameAGI, nGameVIT, nGameDEX, nGameINT, nGameLUK;
         int tempScrollA = 5, tempScrollB = 5, tempScrollC = 5, tempScrollD = 5, tempScrollE = 5, tempScrollF = 5;
         public void actionPerformed(ActionEvent e)//Action Performed Block
              if(e.getSource() == newGameOK)
                   gameState = "Story";
                   newGameGetInfo();
                   newGameStoryPanel.newGameStoryPanelInit();
         public void stateChanged(ChangeEvent e)//Scrollbar Listener Block
              if(e.getSource() == newGameSTR)
                   tempScrollA = 10 - (int)newGameSTR.getValue();
                   newGameINT.setValue(tempScrollA);
              if(e.getSource() == newGameINT)
                   tempScrollA = 10 - (int)newGameINT.getValue();
                   newGameSTR.setValue(tempScrollA);
              if(e.getSource() == newGameAGI)
                   tempScrollA = 10 - (int)newGameAGI.getValue();
                   newGameLUK.setValue(tempScrollA);
              if(e.getSource() == newGameLUK)
                   tempScrollA = 10 - (int)newGameLUK.getValue();
                   newGameAGI.setValue(tempScrollA);
              if(e.getSource() == newGameDEX)
                   tempScrollA = 10 - (int)newGameDEX.getValue();
                   newGameVIT.setValue(tempScrollA);
              if(e.getSource() == newGameVIT)
                   tempScrollA = 10 - (int)newGameVIT.getValue();
                   newGameDEX.setValue(tempScrollA);
              tempScrollA = (int)newGameSTR.getValue();
              tempScrollB = (int)newGameAGI.getValue();
              tempScrollC = (int)newGameVIT.getValue();
              tempScrollD = (int)newGameDEX.getValue();
              tempScrollE = (int)newGameINT.getValue();
              tempScrollF = (int)newGameLUK.getValue();
              nGameSTR.setText("Strength: " + tempScrollA);
              nGameAGI.setText("Agility: " + tempScrollB);
              nGameVIT.setText("Vitality: " + tempScrollC);
              nGameDEX.setText("Dexterity: " + tempScrollD);
              nGameINT.setText("Intelligence: " + tempScrollE);
              nGameLUK.setText("Luck: " + tempScrollF);
         public void setUpAlpha()//Huge block to set up Character creation screen
              int tempProgramLeft = (int)(programWidth /2) - 225;
              int tempProgramRight = (int)(programWidth /2) + 25;
              UIManager.put("Label.foreground", Color.white);
              nGameName = new JLabel("Character Name", JLabel.CENTER);
              nGameName.setBounds((int)((programWidth - 250) / 2), 35, 250, 20);
              nGameRace = new JLabel("Character Race", JLabel.CENTER);
              nGameRace.setBounds(tempProgramLeft, 135, 200, 20);
              nGameGender = new JLabel("Character Gender", JLabel.CENTER);
              nGameGender.setBounds(tempProgramRight, 135, 200, 20);
              nGameSTR = new JLabel("Strength: " + tempScrollA, JLabel.CENTER);
              nGameSTR.setBounds(tempProgramLeft, 230, 200, 20);
              nGameINT = new JLabel("Intelligence: " + tempScrollE, JLabel.CENTER);
              nGameINT.setBounds(tempProgramRight, 230, 200, 20);
              nGameVIT = new JLabel("Vitality: " + tempScrollB, JLabel.CENTER);
              nGameVIT.setBounds(tempProgramLeft, 300, 200, 20);
              nGameDEX = new JLabel("Dexterity: " + tempScrollD, JLabel.CENTER);
              nGameDEX.setBounds(tempProgramRight, 300, 200, 20);
              nGameAGI = new JLabel("Agility: " + tempScrollC, JLabel.CENTER);
              nGameAGI.setBounds(tempProgramRight, 370, 200, 20);
              nGameLUK = new JLabel("Luck: " + tempScrollF, JLabel.CENTER);
              nGameLUK.setBounds(tempProgramLeft, 370, 200, 20);
              newGameOK = new JButton("Start Game", null);
              newGameOK.setHorizontalTextPosition(AbstractButton.CENTER);
              newGameOK.setBackground(Color.black);
              newGameOK.setForeground(Color.white);
              newGameOK.setBounds((int)((programWidth - 100) / 2), 450, 100, 30);
              newGameOK.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.white));
              newGameName = new JTextField("Enter Name", 20);
              newGameName.setFont(new Font("Times New Roman", Font.BOLD, 12));
              newGameName.setForeground(Color.red);
              newGameName.setBackground(Color.black);
              newGameName.setBounds((int)((programWidth - 250) / 2), 60, 250, 25);
              newGameName.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.white));
         //     UIManager.put("ComboBox.foreground", Color.red);
         //     UIManager.put("ComboBox.background", Color.black);
         //     UIManager.put("ComboBox.border", BorderFactory.createMatteBorder(0, 0, 0, 7, Color.white));
              String[] newGameRaceAAA = {"Human", "Elf", "Dwarf"};
              newGameRace = new JComboBox(newGameRaceAAA);
              newGameRace.setSelectedIndex(0);
              newGameRace.setBounds(tempProgramLeft, 160, 200, 20);
              newGameRace.addActionListener(this);
              String[] newGameGenderAAA = {"Male", "Female"};
              newGameGender = new JComboBox(newGameGenderAAA);
              newGameGender.setSelectedIndex(0);
              newGameGender.setBounds(tempProgramRight, 160, 200, 20);
              newGameGender.addActionListener(this);
              UIManager.put("Slider.background", Color.black);
              newGameSTR = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameAGI = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameVIT = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameDEX = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameINT = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameLUK = new JSlider(JSlider.HORIZONTAL, 1, 9, 5);
              newGameSTR.setBounds(tempProgramLeft, 250, 200, 15);
              newGameINT.setBounds(tempProgramRight, 250, 200, 15);
              newGameVIT.setBounds(tempProgramLeft, 320, 200, 15);
              newGameDEX.setBounds(tempProgramRight, 320, 200, 15);
              newGameLUK.setBounds(tempProgramLeft, 390, 200, 15);
              newGameAGI.setBounds(tempProgramRight, 390, 200, 15);
              visiblePanelChecker();
              this.add(newGameOK);
              this.add(newGameName);
              this.add(newGameRace);
              this.add(newGameGender);
              this.add(newGameSTR);
              this.add(newGameAGI);
              this.add(newGameVIT);
              this.add(newGameDEX);
              this.add(newGameINT);
              this.add(newGameLUK);
              this.add(nGameName);
              this.add(nGameRace);
              this.add(nGameGender);
              this.add(nGameSTR);
              this.add(nGameAGI);
              this.add(nGameVIT);
              this.add(nGameDEX);
              this.add(nGameINT);
              this.add(nGameLUK);
              newGameOK.addActionListener(this);
              newGameSTR.addChangeListener(this);
              newGameAGI.addChangeListener(this);
              newGameVIT.addChangeListener(this);
              newGameDEX.addChangeListener(this);
              newGameINT.addChangeListener(this);
              newGameLUK.addChangeListener(this);
              newGameOK.setVisible(true);
              newGameName.setVisible(true);
              newGameRace.setVisible(true);
              newGameGender.setVisible(true);
              newGameSTR.setVisible(true);
              newGameAGI.setVisible(true);
              newGameVIT.setVisible(true);
              newGameDEX.setVisible(true);
              newGameINT.setVisible(true);
              newGameLUK.setVisible(true);
              nGameName.setVisible(true);
              nGameRace.setVisible(true);
              nGameGender.setVisible(true);
              nGameSTR.setVisible(true);
              nGameAGI.setVisible(true);
              nGameVIT.setVisible(true);
              nGameDEX.setVisible(true);
              nGameINT.setVisible(true);
              nGameLUK.setVisible(true);
              repaint();
         public void newGameGetInfo()//Grabs the information from the items in the New Game
              hero = new Chara();
              hero.name = newGameName.getText();
              hero.name = hero.name.trim();
              if(hero.name.length() > 10){hero.name = hero.name.substring(0, 10);}
              hero.race = (String)newGameRace.getSelectedItem();
              hero.gender = (String)newGameGender.getSelectedItem();
              for(int i = 0; i < 2; i ++)
                   hero.strength[i] = tempScrollA;
                   hero.agility[i] = tempScrollB;
                   hero.vitality[i] = tempScrollC;
                   hero.dexterity[i] = tempScrollD;
                   hero.intelligence[i] = tempScrollE;
                   hero.luck[i] = tempScrollF;
              if(hero.race == "Human")
                   hero.strength[2] = 1;
                   hero.agility[2] = 1;
                   hero.vitality[2] = 1;
                   hero.dexterity[2] = 1;
                   hero.intelligence[2] = 1;
                   hero.luck[2] = 1;
              if(hero.race == "Elf")
                   hero.strength[2] = 0;
                   hero.agility[2] = 2;
                   hero.vitality[2] = 0;
                   hero.dexterity[2] = 2;
                   hero.intelligence[2] = 2;
                   hero.luck[2] = 0;
              if(hero.race == "Dwarf")
                   hero.strength[2] = 3;
                   hero.agility[2] = 0;
                   hero.vitality[2] = 2;
                   hero.dexterity[2] = 0;
                   hero.intelligence[2] = 0;
                   hero.luck[2] = 1;
              int hp[] = new int[3];//Min/Max HP
              int mp[] = new int[3];//Min/Max SP
              hero.level = 1;
              hero.job = "Novice";
              hero.status = "Normal";
              hero.property = "Normal";
              for(int i = 0; i < hero.location.length; i++)
                   for(int a = 0; a < hero.location.length; a++)
                        hero.location[i][a] = 320;
              menuActivate();
              resetNewGameStuff();
              visiblePanelChecker();
         public void resetNewGameStuff()//Resets the values in the items for the New Game
              newGameName = null;
              newGameRace = newGameGender = null;
              newGameSTR = newGameAGI = newGameVIT = newGameDEX = newGameINT = newGameLUK = null;
              nGameSTR = nGameAGI = nGameVIT = nGameDEX = nGameINT = nGameLUK = null;

    Is there anybody who can help me? I need Help guys......

  • JComboBox is not visible on JPanel

    I have a class that extends JPanel. Within this class I have added several different components; JLabels, JTextFields, JButtons and a JComboBox.
    All of the added components are visible and working except for the JComboBox. I can see the white background of the box and the popup and its list when I click on the area where the JComboBox is located, but I cannot see the selected text in the box. This seems strange since all the other components surrounding the JComboBox display correctly.
    The background is set to white and the foreground is set to black. It has three options in the popup which are displayed using the foreground color, as it should. When I select an option from the popup, it seems to be working because the next time I display the popup, that selection is highlighted. But the selected text never shows in the box.
    If I create a JComboBox in a JPanel, not an extended class, everything seems to work correctly. I can select from the popup and the selection appears in the box.
    Could you please give me some suggestions as to how to make the selected text in the JComboBox visible?
    Thanks
    Bob

    My layout manager is set to null. I don't think that there is anything obscuring it because the backgroud is visible. The only thing that I can't see it the selected text and the combo box down arrow. I am using VisualCafe to generate this code.
    The extended class is loaded from the following class:
    public class TheSchedule extends javax.swing.JFrame
    using the following code:
         void JButtonGenTimeUnits_actionPerformed(java.awt.event.ActionEvent event)
              JPanelMainPanel.add(new TimeUnitDefinition((Frame)this));
              JPanelMainPanel.repaint();
    The actual code of the TimeUnitDefinition is as follows:
    package com.klawuhn.schedule;
    import javax.swing.*;
    import java.beans.*;
    import java.awt.*;
    import com.symantec.itools.javax.swing.models.StringComboBoxModel;
    import symantec.itools.awt.util.Calendar;
    import com.symantec.itools.javax.swing.borders.LineBorder;
    public class TimeUnitDefinition extends javax.swing.JPanel {
    private Frame parentFrame = null;
         public TimeUnitDefinition(Frame parentFrame)
         this.parentFrame = parentFrame; // Needed when displaying the calendars
              //{{INIT_CONTROLS
              setAlignmentY(1.0F);
              setAlignmentX(1.0F);
              setOpaque(false);
              setLayout(null);
              setSize(457,283);
              JLabelStartDate.setText("Start Date:");
              add(JLabelStartDate);
              JLabelStartDate.setBounds(12,12,156,24);
              JTextFieldStartDate.setDisabledTextColor(java.awt.Color.white);
              JTextFieldStartDate.setToolTipText("This is the date to start generating time units.");
              JTextFieldStartDate.setEditable(false);
              add(JTextFieldStartDate);
              JTextFieldStartDate.setBackground(java.awt.Color.white);
              JTextFieldStartDate.setBounds(168,12,216,24);
              JButtonCalendar1.setText("-");
              JButtonCalendar1.setActionCommand("-");
              add(JButtonCalendar1);
              JButtonCalendar1.setBounds(384,12,24,24);
              JLabelEndDate.setText("End Date:");
              add(JLabelEndDate);
              JLabelEndDate.setBackground(java.awt.Color.cyan);
              JLabelEndDate.setBounds(12,48,156,24);
              JTextFieldEndDate.setDisabledTextColor(java.awt.Color.white);
              JTextFieldEndDate.setToolTipText("This is the date to start generating time units.");
              JTextFieldEndDate.setEditable(false);
              add(JTextFieldEndDate);
              JTextFieldEndDate.setBackground(java.awt.Color.white);
              JTextFieldEndDate.setBounds(168,48,216,24);
              JButtonCalendar2.setText("-");
              JButtonCalendar2.setActionCommand("-");
              add(JButtonCalendar2);
              JButtonCalendar2.setBounds(384,48,24,24);
              JLabelStartTime.setText("Start Time:");
              add(JLabelStartTime);
              JLabelStartTime.setBounds(12,84,156,24);
              JTextFieldStartTime.setToolTipText("This is the time of day to start generating time units.");
              add(JTextFieldStartTime);
              JTextFieldStartTime.setBounds(168,84,240,24);
              JLabelEndTime.setText("End Time:");
              add(JLabelEndTime);
              JLabelEndTime.setBounds(12,120,156,24);
              JTextFieldEndTime.setToolTipText("This is the time of day to end generating time units.");
              add(JTextFieldEndTime);
              JTextFieldEndTime.setBounds(168,120,240,24);
              JLabelUnitOfMeasure.setText("Unit of Measure:");
              add(JLabelUnitOfMeasure);
              JLabelUnitOfMeasure.setBounds(12,156,156,24);
              JComboBoxUnitOfMeasure.setModel(stringComboBoxModel1);
              JComboBoxUnitOfMeasure.setToolTipText("This is the unit of measure used when generating the time units.");
              add(JComboBoxUnitOfMeasure);
              JComboBoxUnitOfMeasure.setBackground(java.awt.Color.white);
              JComboBoxUnitOfMeasure.setForeground(java.awt.Color.black);
              JComboBoxUnitOfMeasure.setBounds(168,156,240,24);
              JLabelBlockSize.setText("Block Size:");
              add(JLabelBlockSize);
              JLabelBlockSize.setBounds(12,192,156,24);
              JTextFieldBlockSize.setText("45");
              JTextFieldBlockSize.setToolTipText("This is the size of the time unit in Unit of Measures.");
              add(JTextFieldBlockSize);
              JTextFieldBlockSize.setBounds(168,192,240,24);
              JButtonSubmit.setText("Submit");
              JButtonSubmit.setActionCommand("Submit");
              JButtonSubmit.setToolTipText("This button will generate the time units.");
              add(JButtonSubmit);
              JButtonSubmit.setBounds(36,228,108,40);
              JButtonCancel.setText("Cancel");
              JButtonCancel.setActionCommand("Cancel");
              JButtonCancel.setToolTipText("This button will discard any changes.");
              add(JButtonCancel);
              JButtonCancel.setBounds(288,228,108,40);
                   String[] tempString = new String[3];
                   tempString[0] = "Days";
                   tempString[1] = "Hours";
                   tempString[2] = "Minutes";
                   stringComboBoxModel1.setItems(tempString);
              //$$ stringComboBoxModel1.move(0,288);
              JComboBoxUnitOfMeasure.setSelectedIndex(2);
              //{{REGISTER_LISTENERS
              SymAction lSymAction = new SymAction();
              JButtonSubmit.addActionListener(lSymAction);
              JButtonCalendar1.addActionListener(lSymAction);
              JButtonCalendar2.addActionListener(lSymAction);
         //{{DECLARE_CONTROLS
         javax.swing.JLabel JLabelStartDate = new javax.swing.JLabel();
         javax.swing.JTextField JTextFieldStartDate = new javax.swing.JTextField();
         javax.swing.JButton JButtonCalendar1 = new javax.swing.JButton();
         javax.swing.JLabel JLabelEndDate = new javax.swing.JLabel();
         javax.swing.JTextField JTextFieldEndDate = new javax.swing.JTextField();
         javax.swing.JButton JButtonCalendar2 = new javax.swing.JButton();
         javax.swing.JLabel JLabelStartTime = new javax.swing.JLabel();
         javax.swing.JTextField JTextFieldStartTime = new javax.swing.JTextField();
         javax.swing.JLabel JLabelEndTime = new javax.swing.JLabel();
         javax.swing.JTextField JTextFieldEndTime = new javax.swing.JTextField();
         javax.swing.JLabel JLabelUnitOfMeasure = new javax.swing.JLabel();
         javax.swing.JComboBox JComboBoxUnitOfMeasure = new javax.swing.JComboBox();
         javax.swing.JLabel JLabelBlockSize = new javax.swing.JLabel();
         javax.swing.JTextField JTextFieldBlockSize = new javax.swing.JTextField();
         javax.swing.JButton JButtonSubmit = new javax.swing.JButton();
         javax.swing.JButton JButtonCancel = new javax.swing.JButton();
         com.symantec.itools.javax.swing.models.StringComboBoxModel stringComboBoxModel1 = new com.symantec.itools.javax.swing.models.StringComboBoxModel();
         class SymAction implements java.awt.event.ActionListener
              public void actionPerformed(java.awt.event.ActionEvent event)
                   Object object = event.getSource();
                   if (object == JButtonSubmit)
                        JButtonSubmit_actionPerformed(event);
                   else if (object == JButtonCalendar1)
                        JButtonCalendar1_actionPerformed(event);
                   else if (object == JButtonCalendar2)
                        JButtonCalendar2_actionPerformed(event);
         void JButtonSubmit_actionPerformed(java.awt.event.ActionEvent event)
              System.out.println("See Submit button");
              TimeUnitCreate timeUnitCreate = new TimeUnitCreate(
              JTextFieldStartDate.getText(),
              JTextFieldEndDate.getText(),
              JTextFieldStartTime.getText(),
              JTextFieldEndTime.getText(),
              (String)JComboBoxUnitOfMeasure.getSelectedItem(),
              JTextFieldBlockSize.getText()
              timeUnitCreate.createTimeUnits();
              this.setVisible(false);
    System.out.println("Done creating Time Units.");
    // (new TimeUnitDefinition()).setVisible(true);
         void JButtonCalendar1_actionPerformed(java.awt.event.ActionEvent event)
         CalendarDialog calendarDialog = new CalendarDialog(parentFrame,"Date",true);
         calendarDialog.show();
         JTextFieldStartDate.setText(calendarDialog.getSelectedDate());
         void JButtonCalendar2_actionPerformed(java.awt.event.ActionEvent event)
         CalendarDialog calendarDialog = new CalendarDialog(parentFrame,"Date",true);
         calendarDialog.show();
         JTextFieldEndDate.setText(calendarDialog.getSelectedDate());
    }

  • How to add a JMenubar and a JTable in a JFrame in a single application

    Hi all,
    I require an urgent help from you.I am a beginer in programming Swing.I want to add a menu,combobox,and a table in a single application.I did coding as below:
    package com.BSS;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    public class newssa extends JFrame
         public JMenuBar menuBar;
         public JToolBar toolBar;
         public JFrame frame;
         private JLabel jLabel1;
         private JLabel jLabel2;
         private JLabel jLabel3;
         private JLabel jLabel4;
         private JLabel jLabel5;
         private JLabel jLabel6;
         private JComboBox jComboBox1;
         private JComboBox jComboBox2;
         private JComboBox jComboBox3;
         private JComboBox jComboBox4;
         private JComboBox jComboBox5;
         private JComboBox jComboBox6;
         private JTable jTable1;
         private JScrollPane jScrollPane1;
         private JPanel contentPane;
         public newssa()
              super();
              initializeComponent();
              this.setVisible(true);
         private void initializeComponent()
              jLabel1 = new JLabel();
              jLabel2 = new JLabel();
              jLabel3 = new JLabel();
              jLabel4 = new JLabel();
              jLabel5 = new JLabel();
              jLabel6 = new JLabel();
              jComboBox1 = new JComboBox();
              jComboBox2 = new JComboBox();
              jComboBox3 = new JComboBox();
              jComboBox4 = new JComboBox();
              jComboBox5 = new JComboBox();
              jComboBox6 = new JComboBox();
              frame=new JFrame();
              //Included here
              JMenuBar menuBar = new JMenuBar();
              JMenu general = new JMenu("General");
         menuBar.add(general);
         JMenu actions =new JMenu("Actions");
         menuBar.add(actions);
         JMenu view=new JMenu("View");
         menuBar.add(view);
         JMenu Timescale=new JMenu("TimeScale");
         menuBar.add(Timescale);
         Timescale.add("Today CTRL+D");
         Timescale.add("Current Week CTRL+W");
         Timescale.add("Current Month CTRL+M");
         Timescale.add("Current Quarter CTRL+Q");
         Timescale.add("Current Year CTRL+Y");
         Timescale.add("Custom TimeScale CTRL+U");
         JMenu start=new JMenu("Start");
         menuBar.add(start);
         JMenu options=new JMenu("Options");
         menuBar.add(options);
         JMenu help=new JMenu("Help");
         menuBar.add(help);
         JFrame.setDefaultLookAndFeelDecorated(true);
         frame.setJMenuBar(menuBar);
         frame.pack();
         frame.setVisible(true);
         toolBar = new JToolBar("Formatting");
         toolBar.addSeparator();
              //Before this included new
              String columnNames[] = { "ColorStatus", "Flash", "Service Order","Configuration","Configuration Description"};
              // Create some data
              String dataValues[][] =
                   { "blue", "flash", "ORT001" },
                   { "AVCONF", "av configuration with warrenty"}
              // Create a new table instance
              //jTable1 = new JTable( dataValues, columnNames );
              jTable1 = new JTable(dataValues,columnNames);
              jScrollPane1 = new JScrollPane(jTable1);
              contentPane = (JPanel)this.getContentPane();
              //scrollPane = new JScrollPane( table );
              //topPanel.add( scrollPane, BorderLayout.CENTER );
              // jLabel1
              jLabel1.setText("Service Centers");
              // jLabel2
              jLabel2.setText("Service Areas");
              // jLabel4
              jLabel3.setText("Skills");
              jLabel4.setText("Availablity Types");
              // jLabel5
              jLabel5.setText("From Date");
              // jLabel6
              jLabel6.setText("To");
              // jComboBox1
              jComboBox1.addItem("Coimbatore");
              jComboBox1.addItem("Chennai");
              jComboBox1.addItem("Mumbai");
              jComboBox1.addItem("New Delhi");
              jComboBox1.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jComboBox1_actionPerformed(e);
              // jComboBox2
              jComboBox2.addItem("North Zone");
              jComboBox2.addItem("South Zone");
              jComboBox2.addItem("Central Zone");
              jComboBox2.addItem("Eastern Zone");
              jComboBox2.addItem("Western Zone");
              jComboBox2.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jComboBox2_actionPerformed(e);
              // jComboBox3
              jComboBox3.addItem("Microsoft Components");
              jComboBox3.addItem("Java Technologies");
              jComboBox3.addItem("ERP");
              jComboBox3.addItem("Others");
              jComboBox3.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jComboBox3_actionPerformed(e);
              // jComboBox4
              jComboBox4.addItem("One");
              jComboBox4.addItem("Two");
              jComboBox4.addItem("Three");
              jComboBox4.addItem("Four");
              jComboBox4.addItem("Five");
              jComboBox4.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jComboBox4_actionPerformed(e);
              // jComboBox5
              jComboBox5.addItem("12/12/2004");
              jComboBox5.addItem("13/12/2004");
              jComboBox5.addItem("14/12/2004");
              jComboBox5.setEditable(true);
              jComboBox5.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jComboBox5_actionPerformed(e);
              // jComboBox6
              jComboBox6.addItem("12/11/2004");
              jComboBox6.addItem("13/11/2004");
              jComboBox6.addItem("14/11/2004");
              jComboBox6.setEditable(true);
              jComboBox6.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jComboBox6_actionPerformed(e);
              // jTable1
              jTable1.setModel(new DefaultTableModel(4, 4));
              // jScrollPane1
              jScrollPane1.setViewportView(jTable1);
              // contentPane
              contentPane.setLayout(null);
              addComponent(contentPane, jLabel1, 2,29,84,18);
              addComponent(contentPane, jLabel2, 201,33,76,18);
              addComponent(contentPane, jLabel3, 384,32,59,18);
              addComponent(contentPane, jLabel4, 2,77,85,18);
              addComponent(contentPane, jLabel5, 197,79,84,18);
              addComponent(contentPane, jLabel6, 384,80,60,18);
              addComponent(contentPane, jComboBox1, 85,32,100,22);
              addComponent(contentPane, jComboBox2, 276,32,100,22);
              addComponent(contentPane, jComboBox3, 419,30,100,22);
              addComponent(contentPane, jComboBox4, 88,76,100,22);
              addComponent(contentPane, jComboBox5, 276,79,100,22);
              addComponent(contentPane, jComboBox6, 421,78,100,22);
              addComponent(contentPane, jScrollPane1, 33,158,504,170);
              // newssa
              this.setTitle("SSA Service Scheduler");
              this.setLocation(new Point(0, 0));
              this.setSize(new Dimension(560, 485));
         /** Add Component Without a Layout Manager (Absolute Positioning) */
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         // TODO: Add any appropriate code in the following Event Handling Methods
         private void jComboBox1_actionPerformed(ActionEvent e)
              int index = jComboBox1.getSelectedIndex();
              switch(index)
                   case 0: System.out.println("Area Coimbatore Selected "); break;
                   case 1: System.out.println("Area Chennai selected"); break;
                   case 2: System.out.println("Mumbai being selected"); break;
                   case 3: System.out.println("New Delhi being selected"); break;
         private void jComboBox2_actionPerformed(ActionEvent e)
              int index = jComboBox2.getSelectedIndex();
              switch(index)
                   case 0: System.out.println("North Zone Selcted "); break;
                   case 1: System.out.println("South Zone being selected"); break;
                   case 2: System.out.println("Central Zone being selected"); break;
                   case 3: System.out.println("Eastern Zone being selected"); break;
                   case 4: System.out.println("Western Zone being selected"); break;
         private void jComboBox3_actionPerformed(ActionEvent e)
              int index = jComboBox3.getSelectedIndex();
              switch(index)
                   case 0: System.out.println("Microsoft Components being selected"); break;
                   case 1: System.out.println("Java Technologies being selected"); break;
                   case 2: System.out.println("ERP Tehnologies being selected"); break;
                   case 3: System.out.println("Other's selected"); break;
         private void jComboBox4_actionPerformed(ActionEvent e)
              int index = jComboBox4.getSelectedIndex();
              switch(index)
                   case 0: System.out.println("One selected"); break;
                   case 1: System.out.println("Two selected"); break;
                   case 2: System.out.println("Three selected"); break;
                   case 3: System.out.println("Four selected"); break;
                   case 4: System.out.println("Five selected"); break;
         private void jComboBox5_actionPerformed(ActionEvent e)
              int index = jComboBox5.getSelectedIndex();
              switch(index)
                   case 0: System.out.println("12/12/2004 being selected"); break;
                   case 1: System.out.println("13/12/2004 being selected"); break;
                   case 2: System.out.println("14/12/2004 being selected"); break;
         private void jComboBox6_actionPerformed(ActionEvent e)
              int index = jComboBox6.getSelectedIndex();
              switch(index)
                   case 0: System.out.println("12/11/2004 being selected"); break;
                   case 1: System.out.println("13/11/2004 being selected"); break;
                   case 2: System.out.println("14/11/2004 being selected"); break;
         public static void main(String[] args)
              newssa ssa=new newssa();
              //JFrame.setDefaultLookAndFeelDecorated(true);
              //JDialog.setDefaultLookAndFeelDecorated(true);
              //JFrame frame = new JFrame("SSA Service Scheduler");
    //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //frame.setJMenuBar(ssa.menuBar);
    //frame.getContentPane( ).add(ssa.toolBar, BorderLayout.NORTH);
    //frame.getContentPane( ).add(ssa.pane, BorderLayout.CENTER);
    //frame.pack( );
    //frame.setVisible(true);
              try
                   //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
    But as a O/P ,I am getting menu in a seperate windos and the rest of the combobox and jtable in a seperate window.Kindly help me to solve the application.
    VERY URGENT PLEASE..
    Thanks in advance
    with kind regds
    Satheesh.K

    But did u mean this as the next problem,Which I will come across..Yes, the second setVisible(true) seemed to be producing a smaller frame behind the main frame.
    And your JMenuBar is declared twice, but not sure if this will affect the code - haven't read it all.

  • Changing value in JcomboBox

    hi, i am new learner in java programming language.
    i trying to develop a Greenwich inn resort reservation system.
    i am adding 2 JCombobox in the JFrame and adding 2 Action listener to the 2 created JCombobox in oder to reset the value in Jcombobox.
    jComboBox1.addActionListener(jcb1);
    jComboBox2.addActionListener(jcb2); i am create a class which call as timemanager to control the time
    public class timemanager {
    int Year;
    int Month;
    int Date;
    Calendar calendar = Calendar.getInstance();
        public timemanager(){
           Date today = new Date();
           Year = (today.getYear() +1900);
           Month = today.getMonth();
           Date = today.getDate();
        public int getmaxday(){
            calendar.set(Year,Month,Date);
            int maxday = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            return maxday;
        }i poiting the object in as timemanager time1 = new timemanager();
    and i am adding the listener command which is
    public ActionListener jcb1=new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            if ((Integer)jComboBox1.getSelectedItem()== (new Date().getYear()+1900)){
             time1.Year = (Integer)jComboBox1.getSelectedItem();
                reservationstartingshowingdate();//method which i call to change the value
             }else{
             time1.Year = (Integer)jComboBox1.getSelectedItem();
             changestartingdatevalue();//method which i call to change the value
        public ActionListener jcb2=new ActionListener(){
        public void actionPerformed(ActionEvent a){
            for(int x =0;x<fullmonth.length;x++){
            if (jComboBox2.getSelectedItem()== fullmonth[x]){
                if (new Date().getMonth()==x){
                    if (time1.Year== (new Date().getYear()+1900)){
                            time1.Month = x;
                         reservationstartingshowingdate(); //method which i call to change the value
                    }else{
                        time1.Month = x;
                        //System.out.println(time1.Month);
                        changestartingdatevalue();
                }else{
                     time1.Month = x;
                     System.out.println(time1.Month);
                     changestartingdatevalue();
        };and my reservationstartingshowingdate() method are
    private void reservationstartingshowingdate() {
                    int date = time1.Date;
                  int month = time1.Month;
                  int year = time1.Year;
                  int maxday = time1.getmaxday();
                  //System.out.println("item count combobox1 ="+jComboBox2.getItemCount());
                  if (jComboBox2.getItemCount()>=0){
                    System.out.println("item count combobox2 ="+jComboBox2.getItemCount());
                      jComboBox2.removeAllItems();
                      jComboBox3.removeAllItems();
                  if(jComboBox1.getItemCount()<=0){
                  for (int x = 0;x<fullyear.length-1;x++){
                        this.jComboBox1.addItem(fullyear[x]);
                  for(int x=month;x<fullmonth.length;x++){
                      System.out.println(x);
                      this.jComboBox2.addItem(fullmonth[x]);
                  System.out.println("finish insert month");
                   for(int x = date;x<=maxday;x++ ){
                         this.jComboBox3.addItem(x);
    //System.out.print(year);
                  this.jComboBox1.setSelectedItem(year);
                }why when i select the same item that with my current year in JCombobox1, Jcombobox2 value will become double? i and calling one time reservationstartingshowingdate() only in jbc1. but why it apper double same data? i am trying to understand the code in action listener. hope you all can explain and solve this problem. thank
    Edited by: yjho on Aug 27, 2010 2:54 AM

    In the future, Swing related questions should be posted in the Swing forum.
    MoreOver, when some other window hides frame, string value in hidden portion of frame get erased.Thats because your painting code is in the actionPerformed() method. Everytime a component is repainted the painting is done from scratch, but of course the code in the actionPerformed() method is not executed.
    You need to do your custom painting by extending JComponent or JPanel. All the actionPerformed method does is tell the component to repaint() itself.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/14painting/index.html]Custom Painting.

  • Event Handling of 2 JComboBoxes in 1 Frame

    Hello,
    thank you very much for your help in the following problem:
    problem: Differntiating events of 2 JComboBoxes in 1 JFrame.
    solution trial: differentiating via information of an Event-object ("list0","list1"). This solution works as stand-alone Frame, but integrating it in menu of another Frame the List-Information turns dependent on the frequency of clicking the JComboBoxes to "list2", "list3",...
    Object o = Event.getSource();
    String ComboInf = String.valueOf(o);
    ComboInf=ComboInf.substring(14,19);//here the 2 ComboBoxes are differentiated
    if(ComboInf.equals("list0")//only works for stand-alone Jframe
    -->ComboBox1
    if(ComboInf.equals("list1")//only works for stand-alone Jframe
    -->ComboBox2Thank you very much again for your answer
    BJoa

    Cast the event source object to what you added the listener to, here JComboBox
        JComboBox comboBox1 = new JComboBox();
        public void actionPerformed(ActionEvent e)
            JComboBox combo = (JComboBox)e.getSource();
            if(combo == comboBox1)
                doSomethingWith comboBox1();
            if(combo == comboBox2)
        }

  • Dynamic resize of JButton and JFrame in response to Font

    Im supposed to increase the font size of the text with JButton by 1 within each click.
    Eventually the text becomes shorter and less visible like WORD becomes WOR... then WO... etc
    How to make the button always resize with text so that the text is fully visible and JFrame always resize with button so that the button doesn't change its position within the Frame ?
    edit:
    I managed to make buttons resize with increasing font
    by making
    JButton b = new JButton("button");
    b.setHorizontalTextPosition(CENTER);
    b.setVerticalTextPosition(CENTER);However the window size doesnt increase with components ;[
    any help would be appretiated.
    Edited by: pimpcane on Dec 11, 2007 12:16 PM

    Ok I managed to get it working moreless by
    adding pack() to the actionPerformed(...) function
    public void actionPerformed(ActionEvent e)
                 int index = Integer.parseInt(e.getActionCommand());
              int size = buttons[index].getFont().getSize();
              size++;
              buttons[index].setFont(new Font(name, style, size));
              pack();
    }The problem is in the task im given it is forbidden to use pack();
    Is there any other method to obtain the same result of JFrame resizing dynamically in response to components resize ?
    Edited by: pimpcane on Dec 12, 2007 12:13 PM
    Edited by: pimpcane on Dec 12, 2007 12:15 PM

  • Hide the title bar on the task bar of a JFrame

    Hi all,
    I have create a JFrame with some controls and implement the functionality on it. Now I want to make some modification on the JFrame(actually on the GUI)
    On the visible of JFrame I can see a title bar of the GUI on the taskbar of my screen. I want to stop/hide that when the JFrame is visible. How can I possible to do it.
    I used Netbeans and there I've not found such a option.
    Thanks

    hiwa wrote:
    Try setUndecorated(true) call.Actually this only remove the frame title bar. Not the title remove on the task bar. I think I'm clear with my original post.

  • JTable CellEditor JComboBox Tab Key

    Hi,
    I use JDK 1.4.1_01 and got a JComboBox as CellEditor inside a JTable.
    Now I tried:
    table.setSurrendersFocusOnKeystroke(true);
    So the table gives up focus to the editor e.g. after the TAB Key is pressed while navigating through the table.
    But there is another Keyboard Event necessary to activate the JComboBox in the Editor (the arrow on the right becomes visible).
    Is there a possibility to make the JComboBox visible right after TAB was pressed?
    Thanks in advance!

    just a guess, didnt try it but... try to set
    public boolean shouldSelectCell(EventObject anEvent)
            return false;
    }in your cell editor
    hope it helps

  • JComboBox Mystery

    I have a main JCombobox in a JFrame that starts up with a set of values. When a user selects an item from the main JComboBox (i.e actionListener, actionPerformed(ActionEvent ae), two other JComboBoxes are filled up with values. Note that the two JComboBoxes did not have any values initially. I am using the removeAllItems() method before I populate the two JComboBoxes.
    My problem is that the values get added to the JComboBoxes more than once, if I use jcbox.addItem(<value>). Instead I tried jcbox.insertItemAt(<value>) and the earlier problem is solved.
    Now the new problem is that I do not know if the values have been added to the JComboBoxes until I click on the arrow to pull down the list of the JComboBoxes. Generally the first value in the list is shown at the top always as default.
    The other problem is that on selection on any item in any of the two JComboBoxes, it does not appear on the top of the list and doesn't even appear to be selected at all.
    Some one please advice what could be done. I need to work on this ASAP.
    All the info I can get would be helpful. Thanks

    Dear Thomas,
    what do you mean, you don't know if the values have been added? didn't your code add them?If you had read thourgh the message properly you wouldn't need to ask this question.
    can you send some code snippet how you setup your 2 jcb'sI have worked out the problem. Right now I have implemented ItemListenerinterface. I have called the itemStateChanged(ItemEvent ie) method. Inside which I have a code that handles my problem real well.
    It is:
    if (ie.getSource() == jcbox && ie.getSelectedItem() == ItemEvent.SELECTED){ }
    Thanks Thomas anyway. UI have added this code so that other's may refer to it.

  • A simple quesiton about editable JComboBox

    Hi...
    I have a editable JCombobox in a JFrame, when the JFrame first open I want the cursor in the JComboBox's editor(text field) and allow the user input value, I used the method requestFocus() of JComboBox, but it just put the focus in the Arrow Button of the JComboBox(not put the cursor in the JComboBox's editor), and the user can not input value.
    So anybody can help me that how to set the postion of the cursor in the JComboBox's editor?
    Thanks in advance!
    lupeng
    [email protected]

    See if this helps .....
         JComboBox c= new JComboBox(){
    public void grabFocus() {
         super.grabFocus();
         getEditor().getEditorComponent().requestFocus();
         c.setEditable(true);
    c.grabFocus();
    //panel.add(c);

  • Need a copy of JComboBox not same referance

    Hi all,
    i need 'n' similar JComboBox in a JFrame. this comBox gets it content from db. so now i need to access db for each JcomBox.
    Is there any a\other method for this?
    How can i get the copy of same JComboBox ? not a ref.
    Pooja

    I am not sure I understand. Do you need a copy of the combobox(the component) or you just need another combobox with the same items?
    If it is the second - create a new combobox, loop over first combo's items and add them to the other.
    Mike

  • Extension of JComboBox was not serializable

    I reduced my example code to a simple extension of JComboBox without any new member. After that the frame was not longer serializeable. There was a workaround for my problem but I still want to know why this exception occurs.

    What's the exception that's occuring? And are you trying to serialize the JComboBox or the JFrame? I don't know much about serialization, but when you serialize an object that contains references to instances of other objects, are the references stored? Maybe when you serialize your frame, the references that it contains to the components it's holding are lost.

  • JComboBox and JFormattedTextField

    Hi ppl.
    I'm trying to set up an input mask in my editable combo.
    I tried this:
    JTextField editorComponent = (JTextField) combo.getEditor().getEditorComponent();
    DefaultFormatterFactory factory = new DefaultFormatterFactory(fmtData);
    ((JFormattedTextField) (JTextField) editorComponent).setFormatterFactory(factory);
    and got on runtime
    javax.swing.plaf.metal.MetalComboBoxEditor$1 cannot be cast to javax.swing.JFormattedTextField
    I tried that and got the same problem:
    JFormattedTextField ftf = new JFormattedTextField(fmtData);
    combo.setEditor((ComboBoxEditor) ftf);
    javax.swing.JFormattedTextField cannot be cast to javax.swing.ComboBoxEditor
    How to handle this errors or how to set up an input mask for combo editor by another way?
    Thanks in advance.

    maybe with this one you can..., but you have to implements change ItemValue
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.math.RoundingMode;
    import java.text.Format;
    import java.text.NumberFormat;
    public class NumberJComboBox implements ComboBoxEditor {
        private JFormattedTextField field;
        private NumberFormat format;
        private JComboBox cb;
        private JFrame frm;
        public NumberJComboBox(Format f) {
            field = new JFormattedTextField(f);
        @Override
        public void addActionListener(ActionListener l) {
        @Override
        public void removeActionListener(ActionListener l) {
        @Override
        public Component getEditorComponent() {
            return field;
        @Override
        public void selectAll() {
        @Override
        public void setItem(Object value) {
            field.setValue(value);
        @Override
        public Object getItem() {
            return field.getValue();
        public NumberJComboBox() {
            format = NumberFormat.getNumberInstance();
            format.setMinimumFractionDigits(2);
            format.setMaximumFractionDigits(2);
            format.setRoundingMode(RoundingMode.HALF_UP);
            NumberJComboBox ncb = new NumberJComboBox(format);
            Double dbl[] = {1002.22, 154.22, 15.4578, 1000.0, 100.00, 0.12};
            cb = new JComboBox(dbl);
            cb.setEditable(true);
            cb.setEditor(ncb);
            frm = new JFrame();
            frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frm.getContentPane().add(cb);
            frm.pack();
            frm.setVisible(true);
        public static void main(String args[]) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    NumberJComboBox calc = new NumberJComboBox();
    }

Maybe you are looking for

  • ICloud not syncing on one computer

    I have two iMacs, a Macbook Air and and iPhone 4. All four were syncing my Calendars and Contacts properly with Moble Me. After transistioning to iCloud, one of my iMacs no longer syncs calendar events properly. It receives updates from the other dev

  • Is there a way to have all (exchange) email on iPad even when offline?

    I would like to have access to my work (exchange) email when offline (travelling). Is there a way of keeping a selected amount on my iPad, not just the most recent items?

  • B2B identifying TP from file name and not Interchange

    We want B2B to identify trading partner from ISA/GS segment, but B2B is taking it from file name. We have property oracle.tip.adapter.b2b.edi.identifyFromTP set to "Interchange". As I understand based on the tip.property it should always take from th

  • HT1212 i have forgot may passcode plz help me ... how to open it?

    i have forgot may passcode plz help me ... how to open it?

  • Lost receipt help!

    Bought a prepaid mobile phone three days ago and the device was not working at my home. I wanted to return the device but I cannot locate the receipt and paid in cash. I can provide the location time and date that the purchase was made but no one see