Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Facing problem with combobox

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Facing problem with combobox

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.List;

    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.JTextField;
    import javax.swing.UIManager;


    public class DTMSrcTgtSelection extends JDialog {

    String type;
    JButton oKBut,canBut;

    //static List<String> srcList, tgtList;

    List<String> connList=DTMCommon.getConnList();
    String[] connArr=connList.toArray(new String[connList.size()]);
    List<String> connList1;
    JComboBox srcConn=new JComboBox(connArr);
    JComboBox tgtConn=new JComboBox(connArr);

    public DTMSrcTgtSelection(String type) {

    this.type=type;

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE) ;
    //srcList=connList;
    //tgtList=connList;

    //srcConn=new JComboBox(srcList.toArray());

    srcConn.setEditable(true);

    /* srcConn.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
    String item=(String) srcConn.getSelectedItem();
    System.out.println(item);
    //System.out.println(tgtConn.getallitems());
    int l=tgtConn.getItemCount();
    System.out.println(l);
    for(int i=0;i<l;i++){
    String name=(String) tgtConn.getItemAt(i);
    System.out.println(name);
    }
    tgtConn.removeItem(item);
    System.out.println();
    int l1=tgtConn.getItemCount();
    System.out.println(l1);
    for(int i=0;i<l1;i++){
    String name=(String) tgtConn.getItemAt(i);
    System.out.println(name);
    }
    // TODO Auto-generated method stub

    }
    });
    */

    //tgtConn=new JComboBox(tgtList.toArray());

    tgtConn.setEditable(true);
    /* tgtConn.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
    String item=(String) tgtConn.getSelectedItem();
    int l=srcConn.getItemCount();
    System.out.println(l);
    for(int i=0;i<l;i++){
    String name=(String) srcConn.getItemAt(i);
    System.out.println(name);
    }

    srcConn.removeItem(item);
    System.out.println();
    int l1=srcConn.getItemCount();
    System.out.println(l1);
    for(int i=0;i<l1;i++){
    String name=(String) srcConn.getItemAt(i);
    System.out.println(name);
    }
    // TODO Auto-generated method stub

    }
    });*/
    // tgtConn=new JComboBox(tgtList.toArray());
    //tgtConn=new JComboBox(connArr);


    //setTitle("Data Masking Utillity");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);


    //code for selected connection should be appear in only one of the source n target comboboxes

    if(type.equals("source")){

    JPanel srcPanel = new JPanel(new GridBagLayout());


    JLabel srcList = new JLabel("Source Connection : ");

    GridBagConstraints constraints1 = DTMCommon.getConstraints(null,
    GridBagConstraints.NONE, GridBagConstraints.WEST,
    0, 0, 0, 0, 0, 0);
    srcPanel.add(srcList,constraints1);
    srcPanel.setBackground(Color.gray);

    constraints1 = DTMCommon.getConstraints(constraints1,
    GridBagConstraints.NONE, GridBagConstraints.WEST,
    0, 1, 0, 0, 0, 0);
    srcPanel.add(srcConn,constraints1);

    srcConn.setEditable(true);

    JPanel OkCancelPane = new JPanel(new GridBagLayout());
    OkCancelPane.setBackground(Color.gray);
    OkCancelPane.setOpaque(true);
    oKBut = new JButton("OK");
    oKBut.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
    String item=(String) srcConn.getSelectedItem();

    tgtConn.removeItem(item);
    //updateConnarr(connArr,item);
    //updateList(srcConn);
    // TODO Auto-generated method stub
    dispose();
    }
    });
    canBut = new JButton("Cancel");
    /*canBut.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e)
    {
    dispose();
    }
    });*/
    OkCancelPane.add(oKBut);
    OkCancelPane.add(canBut);

    JSplitPane srcTgt_ConnButPane_okCancelPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,srcPanel,OkCa ncelPane);
    srcTgt_ConnButPane_okCancelPane.setDividerLocation (65);
    srcTgt_ConnButPane_okCancelPane.setDividerSize(0);
    getContentPane().add(srcTgt_ConnButPane_okCancelPa ne);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setTitle("DTMUtility");
    //setModalityType(ModalityType.APPLICATION_MODAL);
    setLocationRelativeTo(null);
    //setSize(new Dimension(520, 300));
    setSize(new Dimension(400,150));
    setBackground(Color.white);
    setVisible(true);

    }

    if(type.equals("target")){


    JPanel tgtPanel = new JPanel(new GridBagLayout());

    JLabel tgtList = new JLabel("Target Connection : ");

    GridBagConstraints constraints1 = DTMCommon.getConstraints(null,
    GridBagConstraints.NONE, GridBagConstraints.WEST,
    0, 0, 0, 0, 0, 0);
    tgtPanel.add(tgtList,constraints1);
    tgtPanel.setBackground(Color.gray);

    constraints1 = DTMCommon.getConstraints(constraints1,
    GridBagConstraints.NONE, GridBagConstraints.WEST,
    0, 1, 0, 0, 0, 0);
    tgtPanel.add(tgtConn,constraints1);

    JPanel OkCancelPane = new JPanel(new GridBagLayout());
    OkCancelPane.setBackground(Color.gray);
    OkCancelPane.setOpaque(true);
    oKBut = new JButton("OK");
    oKBut.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
    String item=(String) tgtConn.getSelectedItem();

    srcConn.removeItem(item);
    //updateList(srcConn);
    // TODO Auto-generated method stub
    dispose();
    }
    });
    canBut = new JButton("Cancel");
    /*canBut.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e)
    {
    dispose();
    }
    });*/
    OkCancelPane.add(oKBut);
    OkCancelPane.add(canBut);


    JSplitPane srcTgt_ConnButPane_okCancelPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,tgtPanel,OkCa ncelPane);
    srcTgt_ConnButPane_okCancelPane.setDividerLocation (65);
    srcTgt_ConnButPane_okCancelPane.setDividerSize(0);
    getContentPane().add(srcTgt_ConnButPane_okCancelPa ne);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setTitle("DTMUtility");
    //setModalityType(ModalityType.APPLICATION_MODAL);
    setLocationRelativeTo(null);
    setSize(new Dimension(400,150));
    setBackground(Color.white);
    setVisible(true);

    }




    }

    protected void updateConnarr(String[] connArr2, String item) {
    connArr2=connArr;

    // TODO Auto-generated method stub

    }






    }




    above code when i will click on source from menu the selected item should not appear in the target and vice versa . action also firing but the problem is the target r source combobox also disappearing all the items including the removed item..plz help me to get out of this..


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Facing problem with combobox

    Firstly, this belongs in the AWT / Swing subforum. Don't make another thread now, just remember for future posting.

    Secondly, please use highlight tags to surround your code in so that it is easy to read. Right now it would take hours to decipher your code. Use highlight tags like this:

    [highlight=Java]//your code here[/highlight]

    Finally, you'll need to be more explicit in the description of your problem. What variables are the issue? Are you getting errors (if so, post them)?
    Last edited by snowguy13; February 16th, 2012 at 07:01 AM.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,296
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Facing problem with combobox

    Thread moved to the appropriate forum, and ditto snowguy's post

Similar Threads

  1. Combobox Problem
    By hurleyga in forum AWT / Java Swing
    Replies: 1
    Last Post: December 7th, 2011, 07:55 AM
  2. I am Facing problem in Scanner Class
    By snithishkumar in forum Java SE APIs
    Replies: 2
    Last Post: October 11th, 2011, 09:39 AM
  3. combobox unicode problem
    By trexi in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: January 18th, 2011, 10:06 AM
  4. Java Web Browser Term Project- I am facing multiple problem...pls help
    By tazbinur in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 8th, 2010, 09:05 AM
  5. Facing problem with posting Excel file for download - Content in browser
    By ragz_82 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 9th, 2010, 07:28 AM