+ Reply to Thread
Results 1 to 10 of 10

Thread: JComboBox - Simple Version !

  1. #1
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    JComboBox - Simple Version !

    Hey C.C, I hope you enjoy tutorials since I enjoy to share knowledge with others hope you guys feel the same !

    Today I will try to introduce you guys to JComboBox with Editable boxes, FUN !

    So let's get started !

    Since I presume people have worked around with the swing package so making this wouldn't/shouldn't be a bother for you guys to understand !
    However I will do my best to make it understand able !

    The imports
    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    Here we are importing the parts needed to create our application !
    Swing for the gui, awt for allowing us setting up layouts ! awt.event for allowing us to see changes/change/edit/listen !

    The variables we need for our function !
    Code:
    JComboBox Answer = new JComboBox();
    JLabel Welcome = new JLabel();
    So here is our Box that we are going to use !
    JComboBox is common used when making a text list, example, name list; type your name check in others just view it up !
    JLabel is simple, a label containing just pure text !

    Layout
    Code:
    	public TestTest() {
    		setLayout(new FlowLayout());
    		add(new JLabel("What's your name?",JLabel.RIGHT));
    		add(Answer);
    		add(Welcome);
    		Welcome.setHorizontalAlignment(JLabel.LEFT);
    		Answer.setEditable(true);
    		Answer.addActionListener(this);
    		setSize(350,90);
    		setVisible(true);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    	}
    The public part is our constructor(since we need to create a layout it will always be done by our constructor !)
    By applying a flowlayout we will be able to set a "flow" in the frame !
    Hence we will be able to use the layout whenever we want, kinda dynamically.
    By using Add we add them to our layout and after we have added we have to give them proper position !
    As I have been talking about our box will be editable meaning we can enter how much information we want to and it will remember it.
    Adding the ActionListener will allow us to view "changes" clicks,and movements !
    setSize is no problem nor setVisible same goes with setDefaultCloseOperation !
    Simple things that should be understood !

    Our listener, while making applications and want to make it "do" something.
    Code:
    public void actionPerformed(ActionEvent e) {
    		String Name = (String) Answer.getSelectedItem();
    		Welcome.setText("Welcome "+Name+" to CodeCall!");
    		Answer.addItem(Name);
    	}
    While we listing for event changes, while it happens it will add in our text to the box and print out a "welcome" phrase !

    The Main
    Code:
    	public static void main(String[] arg) {
    		TestTest Test = new TestTest();
    	}
    }
    So I hope you guys enjoy this tutorial as I did !

    Also the whole code!
    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    JComboBox Answer = new JComboBox();
    JLabel Welcome = new JLabel();
    public TestTest() {
    		setLayout(new FlowLayout());
    		add(new JLabel("What's your name?",JLabel.RIGHT));
    		add(Answer);
    		add(Welcome);
    		Welcome.setHorizontalAlignment(JLabel.LEFT);
    		Answer.setEditable(true);
    		Answer.addActionListener(this);
    		setSize(350,90);
    		setVisible(true);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    	}
    public void actionPerformed(ActionEvent e) {
    		String Name = (String) Answer.getSelectedItem();
    		Welcome.setText("Welcome "+Name+" to CodeCall!");
    		Answer.addItem(Name);
    	}
    	public static void main(String[] arg) {
    		TestTest Test = new TestTest();
    	}
    }
    Screenie for you guys
    JComboBox - Simple Version !-output.png

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: JComboBox - Simple Version !

    Nice job! +rep

  4. #3
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: JComboBox - Simple Version !

    Quote Originally Posted by Jordan View Post
    Nice job! +rep
    Thank you !

  5. #4
    Join Date
    Nov 2008
    Location
    Kosovo.
    Posts
    2,391
    Rep Power
    30

    Re: JComboBox - Simple Version !

    Great Job , Turk4n .. +rep

  6. #5
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: JComboBox - Simple Version !

    nice job mate .. and +rep

  7. #6
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: JComboBox - Simple Version !

    Quote Originally Posted by mendim. View Post
    Great Job , Turk4n .. +rep
    Thanks
    Quote Originally Posted by Egz0N View Post
    nice job mate .. and +rep
    Thank you

  8. #7
    arslan220 Guest

    Re: JComboBox - Simple Version !

    thanks for that.

  9. #8
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: JComboBox - Simple Version !

    Quote Originally Posted by arslan220 View Post
    thanks for that.
    Lol, thanks why so banned?

  10. #9
    Miharu is offline Newbie
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Re: JComboBox - Simple Version !

    Thanks +rep

  11. #10
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: JComboBox - Simple Version !

    Quote Originally Posted by Miharu View Post
    Thanks +rep
    You are welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. CodeCall's First Applet - Simple Version !
    By Turk4n in forum Java Tutorials
    Replies: 13
    Last Post: 01-15-2009, 01:09 AM
  2. ArrayList - Simple version !
    By Turk4n in forum Java Tutorials
    Replies: 14
    Last Post: 01-09-2009, 04:57 AM
  3. Abstract method(SIMPLE VERSION)
    By Turk4n in forum Java Tutorials
    Replies: 2
    Last Post: 09-20-2008, 12:35 AM
  4. Tutorial paint dots(simple version)
    By Turk4n in forum Java Tutorials
    Replies: 6
    Last Post: 06-25-2008, 11:07 PM
  5. Replies: 1
    Last Post: 01-29-2008, 11:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

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