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

x
?
Solved

Combobox solution please

Posted on 1999-09-06
4
Medium Priority
?
168 Views
Last Modified: 2012-05-05
I have a combobox to which i am adding values, for example

JComboBox jb = new JComboBox();
jb.addItem("first");
jb.addItem("second");

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....

Thanks
Srini
0
Comment
Question by:seenuv
[X]
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
4 Comments
 
LVL 16

Expert Comment

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

take a look at SwingSet example applet.
0
 
LVL 5

Expert Comment

by:sgoms
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{
    InternalMenu(){
                setSize(400,300);
                        setTitle("Set Focus");
                JLabel lbl=new JLabel("This frame has got the menu on a panel");
                        getContentPane().add(lbl,BorderLayout.NORTH);
                        getContentPane().add(new menuPanel(),BorderLayout.CENTER);
                        addWindowListener(new WindowAdapter(){
                            public void windowClosing(WindowEvent e){
                                       dispose();
                                    }
                        });
            }
            class menuPanel extends JPanel{
                        menuPanel(){
                                    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"));
                                    menubar.add(menu);
                                    add(menubar);
                        }
            }
            public static void main(String args[]){
              ( new InternalMenu()).setVisible(true);
            }
}
0
 
LVL 1

Expert Comment

by:BillyAbbott
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.
0
 
LVL 2

Accepted Solution

by:
shaveri earned 40 total points
ID: 2153204
Try this....

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

public class PanelMenu extends JFrame{
     PanelMenu(){
      JPanel p=new JPanel();            
      JMenuBar menubar=new JMenuBar();
      JMenu menu=new JMenu("first");
      menu.add(new JMenuItem("second"));
      menu.add(new JMenuItem("third"));
      menubar.add(menu);
      p.add(menubar);      
      getContentPane().add(p,BorderLayout.CENTER);
              setSize(200,200);
              setTitle("Combo replacement");
                  setVisible(true);      
      }
                                 
     public static void main(String args[]){
             new PanelMenu();
      }
}
0

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