Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Combobox solution please

Posted on 1999-09-06
Medium Priority
Last Modified: 2012-05-05
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....

Question by:seenuv
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Expert Comment

ID: 2025767
you CAN put a menu inside Swing JApplet.

take a look at SwingSet example applet.

Expert Comment

ID: 2027049
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);

Expert Comment

ID: 2030157
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.

Accepted Solution

shaveri earned 40 total points
ID: 2153204
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();

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question