Results 1 to 4 of 4

Thread: JCombobox

  1. #1
    NajwaMy is offline Member
    Join Date
    Jul 2013
    Posts
    13
    Rep Power
    0

    Default JCombobox

    I have a list selection combined in a combo box..However I've got this error

    Name1.java:15: error: illegal forward reference
    JComboBox ColorList=new JComboBox(option);
    ^
    Note: Name1.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error

    Here's my code :

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


    public class Name1 extends JFrame
    implements ActionListener
    {

    JButton btn1=new JButton("OK");
    JLabel lbl=new JLabel("Enter your name");
    JTextField txtfield=new JTextField(20);
    JCheckBox chkbox=new JCheckBox("Bold");
    JRadioButton radiobtn=new JRadioButton("Red");
    JComboBox ColorList=new JComboBox(option);
    String option[]={"Red","Green","Blue"};
    JTextArea txtarea=new JTextArea();
    Font font = new Font("Verdana", Font.BOLD, 12);


    public Name1()
    {

    setLayout(new FlowLayout(FlowLayout.LEFT,0,0));

    add(btn1);
    add(lbl);
    add(txtfield);
    add(chkbox);
    add(radiobtn);
    add(ColorList);
    add(txtarea);



    btn1.addActionListener(this);
    //txtfield.addActionListener(this);



    }

    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == btn1)
    {
    String nameinput=txtfield.getText();
    txtarea.setText(nameinput);
    if(radiobtn.isSelected())
    txtarea.setForeground(Color.RED);
    else if(chkbox.isSelected())
    txtarea.setFont(font);
    }



    }

    public static void main(String[] args)
    {
    Name1 obj=new Name1();
    obj.setTitle("LAB 3 Q2");
    obj.setVisible(true);
    obj.pack();
    }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,693
    Rep Power
    8

    Default Re: JCombobox

    When posting code, please use the code tags.

    The error you listed is complaining that you're trying to use the option variable before you define it.

    You're also getting a warning about not using generics on your JComboBox.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    NajwaMy is offline Member
    Join Date
    Jul 2013
    Posts
    13
    Rep Power
    0

    Default Re: JCombobox

    I don't understand about the code tags? How can i fix the error?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: JCombobox

    Quote Originally Posted by NajwaMy View Post
    I don't understand about the code tags?
    Ever thought of looking around the site to see what you might find?

    Guide For New Members
    BB Code List - Java Programming Forum - Learn Java Programming

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Need help for a jcombobox
    By Alexis in forum AWT / Swing
    Replies: 4
    Last Post: 09-16-2011, 02:13 AM
  2. Replies: 2
    Last Post: 12-10-2009, 01:58 PM
  3. JComboBox
    By pinks_70986 in forum New To Java
    Replies: 2
    Last Post: 02-19-2009, 05:26 PM
  4. I need help with JComboBox
    By eva21 in forum New To Java
    Replies: 1
    Last Post: 11-28-2008, 10:05 PM
  5. jcombobox
    By Freddie in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2007, 12:48 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •