• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

Combobox solution please

I have a combobox to which i am adding values, for example

JComboBox jb = new JComboBox();

when i view that in the applet the firstitem is "first" and when i drag the menu therealso the first item is "first" idont want that i wanna one similar to menu since we cant put a menu ina applet i am going for combobox how shall i get rid of the first element i tried with setSelectedIndex too it is showing the nth item specified i dont want that too the first item to be displayed and when i drag i dont need that first item again, how shall i go it.  Please help me to solve this error.  Please....

1 Solution
you CAN put a menu inside Swing JApplet.

take a look at SwingSet example applet.
To take a leaf out of the example,
U can simply add a JMenuBar to a JPanel.
Here is an example..
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
//import javax.swing.border.*;

public class InternalMenu extends JFrame{
                        setTitle("Set Focus");
                JLabel lbl=new JLabel("This frame has got the menu on a panel");
                        getContentPane().add(new menuPanel(),BorderLayout.CENTER);
                        addWindowListener(new WindowAdapter(){
                            public void windowClosing(WindowEvent e){
            class menuPanel extends JPanel{
                                    JMenuBar menubar=new JMenuBar();
                                    JMenu menu=new JMenu("Item 1");
                                    menu.add(new JMenuItem("Item 2"));
                                    menu.add(new JMenuItem("Item 3"));
                                    menu.add(new JMenuItem("Item 4"));
                                    menu.add(new JMenuItem("Item 5"));
            public static void main(String args[]){
              ( new InternalMenu()).setVisible(true);
if you want to remove an item from a combo use the removeItem(object) or removeItemAt(index) methods.

is that what you are trying to do?

use JApplet if you can though, it's much easier, and combos make bad looking menus.
Try this....

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class PanelMenu extends JFrame{
      JPanel p=new JPanel();            
      JMenuBar menubar=new JMenuBar();
      JMenu menu=new JMenu("first");
      menu.add(new JMenuItem("second"));
      menu.add(new JMenuItem("third"));
              setTitle("Combo replacement");
     public static void main(String args[]){
             new PanelMenu();
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now