Need Help solving this issue

Hey everyone. I'm new to Java and I'm experimenting with JCombo box in a timesheet program I'm trying to make. Can someone please tell me why, in the following code, if i enter text to the JComboBox and hit enter, it adds an item two times to the list, and creates two buttons, but if i select an item from the list it adds the item back to the list once and only creates one button.
I would prefer to have just one button created as well as have a selection from the drop down list not be added back in. I'm confused as to how to implement this though because it would seem to me that an action listener on the combo box would listen for both the key event and the dropdown selection.
The code
package timesheet;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JComponent;
import java.awt.Toolkit;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
* @author Jamie Snipes
public class Main extends JFrame implements ActionListener{
public static void main(String[] args) {
new Main().setVisible(true);
/** Creates a new instance of Main */
public Main() {
initComponents();
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation(new Point((screenSize.width - frameSize.width),
(screenSize.height - frameSize.width)/ 6 ));
* @param args the command line arguments
private void initComponents() {
mainPanel = new javax.swing.JPanel();
mainPanel.setLayout(new BorderLayout());
eventTrackerPanel = new javax.swing.JPanel();
//eventTrackerPanel.setLayout(new GridLayout(5,1, 5, 5));
projectTitleLabel = new javax.swing.JLabel();
buttonsPanel = new javax.swing.JPanel();
buttonsPanel.setLayout(new BorderLayout());
newItemPanel = new javax.swing.JPanel();
newItemPanel.setLayout(new FlowLayout());
startButton = new javax.swing.JButton("Start");
notesButton = new javax.swing.JButton("Add Note");
stopButton = new javax.swing.JButton("Stop");
menuBar = new javax.swing.JMenuBar();
menuItem= new javax.swing.JMenuItem("Exit");
menu= new javax.swing.JMenu("File");
addTimeSheetItem= new javax.swing.JButton("Add") ;
projectArray= new String[10];
removeProjectButton=new javax.swing.JButton("remove") ;
setTitle("Time Sheet");
//Menu Bar Itmes
// menu.setMnemonic(KeyEvent.VK_A);
// menu.getAccessibleContext().setAccessibleDescription();
menuBar.add(menu);
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==menuItem){
exitMenuItemActionPerformed(evt);
menu.add(menuItem);
setJMenuBar(menuBar);
mainPanel.setLayout(new java.awt.BorderLayout());
mainPanel.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(5, 5, 5, 5)));
mainPanel.setMinimumSize(new java.awt.Dimension(800, 800));
projectTitleLabel.setText("Project Name:");
//Top Panel
projectNameBox= new javax.swing.JComboBox();
projectNameBox.setEditable(true);
eventTrackerPanel.setLayout(new GridLayout(0,1, 5, 5));
projectNameBox.addActionListener(this);
eventTrackerPanel.add(projectNameBox);
newItemPanel.add(projectNameBox);
newItemPanel.add(addTimeSheetItem);
// buttonsPanel (Bottom) Panel
buttonsPanel.add(startButton, BorderLayout.WEST);
buttonsPanel.add(notesButton, BorderLayout.CENTER);
buttonsPanel.add(stopButton, BorderLayout.EAST);
// Main Panel
mainPanel.add(newItemPanel, BorderLayout.NORTH);
mainPanel.add(eventTrackerPanel, BorderLayout.CENTER);
mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(mainPanel);
getContentPane().setSize(800, 800);
public void actionPerformed(ActionEvent e){
if(e.getSource()==projectNameBox){
for(int i=0; i<=100; i++){
selectedProjectToggleButton= new javax.swing.JToggleButton[100];
projectArray= new String();
selectedProjectToggleButton= new javax.swing.JToggleButton();
projectArray=(String)projectNameBox.getSelectedItem();
System.out.println(projectArray);
projectNameBox.addItem(projectArray);
selectedProjectToggleButton.setText(projectArray);
eventTrackerPanel.add(selectedProjectToggleButton);
return;
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
// Variables declaration - do not modify
private javax.swing.JPanel buttonsPanel;
private javax.swing.JPanel newItemPanel;
private javax.swing.JPanel eventTrackerPanel;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JLabel feedbackLabel;
public javax.swing.JMenu fileMenu;
private javax.swing.JButton[] buttonArray;
private javax.swing.JButton startButton;
private javax.swing.JButton stopButton;
private javax.swing.JButton notesButton;
private javax.swing.JButton addTimeSheetItem;
private javax.swing.JButton removeProjectButton;
private javax.swing.JLabel projectTitleLabel;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem menuItem;
private javax.swing.JMenu menu;
private javax.swing.JComboBox projectNameBox;
private java.awt.event.ActionListener isClicked;
private int i;
private javax.swing.JToggleButton[] selectedProjectToggleButton;
private String[] projectArray;
private java.lang.Boolean projectEntered;
private String projectName;
// End of variables declaration
}

make this the 1st line of your actionPerformed method...
System.out.println(e.getActionCommand());
You will see that when you type in the box and then click ADD it makes 2 things happen.
comboBoxEdited
comboBoxChanged
And when you select from the drop down list all you get is 1 thing
comboBoxChanged
Just put an IF statement in there that only looks for "comboBoxChanged" actions and then it should work.

Similar Messages

  • I've installed CS6 and web Premium on a Mac running 10.9.5, and Dreamweaver,Flash and Illustrator wont launch.  All other components work normally.  In Activity monitor it says Adobe switchboard failed to respond.  Can anyone help solve this issue?

    I've installed CS6 and web Premium on a Mac running 10.9.5, and Dreamweaver,Flash and Illustrator wont launch.  All other components work normally.  In Activity monitor it says Adobe switchboard failed to respond.  Can anyone help solve this issue?

    Release: 4/25/2012
    http://support.amd.com/us/gpudownload/windows/Pages/radeonmob_win7-64.aspx

  • HT4101 Connecting my lightning to sd card reader accessoire THE iPad air Lets know' this accessory is not. supported by this iPad' could Someren help solving this issue?

    Connecting my lightning to sd card reader accessoire THE iPad air Lets know' this accessory is not. supported by this iPad' could Someren help solving this issue?

    Thanks for the advice. Unfortunately it didn't work. Have tried both kinds of restore. First restoring from backup and second as a new device (twice). Still get the same "Accessory not supported" message. Thank goodness I can use the old 30 pin SD reader with the lightning adaptor for my up-coming trip. I tried it again and it worked again. BUT I hate having a piece of Apple equipment that doesn't work.

  • My ipad turns off randomly and doesnt turn back on and wont restore with itunes and i tried holding the power and home button down and i see a faint apple logo than it disappears and still does not operate please help solve this issue

    My ipad turns off randomly and doesnt turn back on and wont restore with itunes and i tried holding the power and home button down and i see a faint apple logo than it disappears and still does not operate please help solve this issue

    i have the same problem...my ipod is 4th generation?uggghhhhh

  • Have upgraded to iTunes 11 and now can't determine how to printout the listing of songs on my playlists.  I admit to being a 73 year old novice.  I need help on this issue. Step by step help would be appreciated.

    I just upgraded to iTunes 11, and now I can't printout the song listings on my playlists.  It was easy for me on the earlier version of iTunes.  I am a 73 year old novice and need help.  A step by step explanatuion would really help.  Bless whoever can help me.

    Select all the songs in the playlist concerned. Ctrl + A is the normal shortcut.
    Select File > Print from the top menu
    Select the option of Song List in the dialog box
    Click Print

  • Services disappearing? Need help solving this.

    Over the years I have created many Services (using automator and applescript), so that when you right click a folder or file you have the option to click on the service.
    However In the recent weeks it has come up where sometimes the Service field disappears. How I get them back is logging out and then logging back in.
    Does this mean I have some virus or something? Is there a way to handle this?
    Here is what is supposed to come up:
    Here is what happens sometimes:
    Thanks guys

    How often do you need to do this? I think that a script which would work properly may be more work than is worth the time.
    I'm sure something like this could be done, but the real problem would be what would the next group of lines that you run the script on look like? Would a script that works for this circumstance work properly for another shape?
    Here's some parameters to think about:
    How do you determine which line segments (or endpoints) in the document need to be connected? All points in the document, or will you be working with a selection?
    Once you determine the points (eliminating all that are already connected), how do you want them connected, and which point do you start with? Connect to the closest available point would seem what you want, but depending on how you determine which point to start with could give you different results.
    You might want to loop through all eligible points, and save the distance to every other point into an array. Then, loop through connecting the 2 closest available points until you've connected every point.

  • Need help solving this tricky connect paths problem!

    I need to convert a bunch of separate paths  in particular way so they create one single continuos path as shown in the attached PNG file.
    It has me stumped. Does anyone know of a way to do this via scripting?

    How often do you need to do this? I think that a script which would work properly may be more work than is worth the time.
    I'm sure something like this could be done, but the real problem would be what would the next group of lines that you run the script on look like? Would a script that works for this circumstance work properly for another shape?
    Here's some parameters to think about:
    How do you determine which line segments (or endpoints) in the document need to be connected? All points in the document, or will you be working with a selection?
    Once you determine the points (eliminating all that are already connected), how do you want them connected, and which point do you start with? Connect to the closest available point would seem what you want, but depending on how you determine which point to start with could give you different results.
    You might want to loop through all eligible points, and save the distance to every other point into an array. Then, loop through connecting the 2 closest available points until you've connected every point.

  • Need help on this issue.

    Hi Experts & Dear Matt,
    Sorry for posting a request/thread (repost) like this.
    but my situation is worst now, I am trying in different ways but have no solution yet.
    It a minor problem where i dont know to correct, so getting problem(Pressure, Extra time used) from my higher authorities.
    So please help me out by this situation.
    My problem : I already posted a Thread, and I am reposting here again sorry for doing like this..
    My thread :
    Hi Experts,
    I have a problem in SMARTforms,
    First my requirement is Label Printing,(3 per page) I/p selection is MATNR & PLANT & LGORT.
    OUTPUT is full Classification details wth two Logo's on each label(total 6 logos per page)
    I managed to get all the data into Final table(materials) and I am passing 3 materials at a time to FORM.
    through loop & endloop. in between Loop I am calling my smart form,
    My ITAB Structire is
    MATNR1, LGORT1,MATNR2, LGORT2,MATNR3, LGORT3,
    MATNR1, LGORT1,MATNR2, LGORT2,MATNR3, LGORT3,
    MATNR1, LGORT1,MATNR2, LGORT2,MATNR3, LGORT3,
    MATNR1, LGORT1,MATNR2, LGORT2,MATNR3, LGORT3,
    MATNR1, LGORT1,MATNR2, LGORT2,MATNR3, LGORT3,
    My problem is If user inputs upto 3 matnrs. its working fine.
    when he enters more than 3 lets say 7.
    first its showing print settings screen, when i select print preview, It shows the output fine(1,2,3Materials.)
    but only One page. When I click on back, again its showing print settings, if I click print preview,
    It shows the next 3 materials(4,5,6Materials), and when I click back again print settings finally 1 materials(7th).
    My requirement is when I click on print preview, It should show 3 pages at a time instead of the above.
    -Dunlop

    Hi Sai,
    Here comes the major problem,
    After passing the variable to smartform as mentioned, I am retriving the data again like this
    now I need to show both the passing variable and the retived variables,
    retrived data is always 20-30 records, (classification of materials)
    so i am making a loop here, to print classification. so i am doing this three time for three logos..
    Hope you understand my problem now clearly.
    TABLES : KSML,AUSP, CABN.
    DATA: BEGIN OF T_TEMP OCCURS 0,
            CLASS LIKE KLAH-CLASS,         "Class number
            KLART LIKE KLAH-KLART,         "Class type
            CLINT LIKE KLAH-CLINT,         "Internal class number
          END OF T_TEMP.
    DATA : IT_TEXT3 TYPE TABLE OF TY_TEXT,
           WA_TEXT3 LIKE LINE OF IT_TEXT3.
    DATA : CNT1(2), CNT(2) .
    DATA : IT_FINAL TYPE TABLE OF TY_FINAL, WA_FINAL LIKE LINE OF IT_FINAL.
    Get the classification details KSSK and KLAH.
    SELECT SINGLE SCLASS SKLART L~CLINT INTO
        (T_TEMP-CLASS, T_TEMP-KLART, T_TEMP-CLINT)
    FROM KSSK AS L INNER JOIN KLAH AS S ON SCLINT EQ LCLINT
    WHERE L~OBJEK EQ GV_MATNR.
    CLEAR :IT_TEXT[],WA_TEXT.
    retrieve characteristics info of a class
    SELECT * FROM KSML WHERE CLINT = T_TEMP-CLINT
                         AND KLART = T_TEMP-KLART.
    retrieve characteristics value info
      SELECT * FROM AUSP WHERE OBJEK = GV_MATNR
                           AND ATINN = KSML-IMERK
                           AND KLART = KSML-KLART.
    retrieve characteristics info
        SELECT SINGLE * FROM CABN WHERE ATINN = AUSP-ATINN.
        MOVE CABN-ATNAM TO WA_TEXT-ATNAM. "Characteristics desc.
        MOVE AUSP-ATWRT TO WA_TEXT-ATWRT. "Characteristics Value
        MOVE CABN-ATINN TO WA_TEXT-ATINN.
        APPEND WA_TEXT TO IT_TEXT.
        CLEAR: WA_TEXT.
      ENDSELECT.                         "ausp
    ENDSELECT.
    DELETE IT_TEXT WHERE ATWRT IS INITIAL.
    LOOP AT IT_TEXT INTO WA_TEXT.
      SELECT SINGLE ATBEZ INTO WA_TEXT-ATBEZ FROM CABNT
      WHERE ATINN = WA_TEXT-ATINN AND SPRAS = 'EN' . "SY-LANGU.
      MODIFY IT_TEXT FROM WA_TEXT.
      CLEAR WA_TEXT.
    ENDLOOP.
    LOOP AT IT_TEXT INTO WA_TEXT.
      CNT1 = CNT1 + 1.
    ENDLOOP.
    IF IT_TEXT IS NOT INITIAL.
      LOOP AT IT_TEXT INTO WA_TEXT.
        CNT = SY-TABIX MOD 2.
        IF CNT EQ 0.
          MOVE WA_TEXT-ATWRT TO WA_TEXT3-ATWRT1.
          MOVE WA_TEXT-ATBEZ TO WA_TEXT3-ATBEZ1.
          APPEND WA_TEXT3 TO IT_TEXT3.
          CLEAR : WA_TEXT3.
        ELSE.
          MOVE WA_TEXT-ATWRT TO WA_TEXT3-ATWRT.
          MOVE WA_TEXT-ATBEZ TO WA_TEXT3-ATBEZ.
        ENDIF.
      ENDLOOP.
      CNT = CNT1 MOD 2.
      IF CNT NE 0.
        APPEND WA_TEXT3 TO IT_TEXT3.
        CLEAR : WA_TEXT3.
      ENDIF.
      CLEAR : IT_TEXT[].
      IT_TEXT[] = IT_TEXT3[].
    ENDIF.
    -Dunlop

  • My bluetooth is stuck on searching. Need help on this issue?

    I have been facing issues with the Bluetooth on my iPhone 4. I recently upgraded to 6.1.2 and the bluetooth is stuck on searching and never shows up phones around. Can you please provide a solution or fix for this. I did restart the phone and resetting all the settings.

    It will not connect to other phones.  This has never been a feature of iphone.
    It will stop searhcing when you hit the home button or back out of the bluetooth screen.

  • I need help solving this problem!!

    Hi, i'm new to java and have written only a few programs, i recently wrote one and had the following error but dont know why...........
    Exception in thread "main" java.lang.NoClassDefFoundError: quadraticsolverApp
    I have included my code below.....
    import java.applet.Applet;
    public class quadraticsolver extends Applet
    public double a, b, c ;
    public void init()
    a=0;
    b=0;
    c=0;
    public String getRoot1()
    if (getDescriminent() < 0.0 || this.a == 0.0)
    return "" + ((-b + Math.sqrt(-getDescriminent()))/(2 * a)) + " i";
    else
    return "" + ((-b + Math.sqrt(getDescriminent()))/(2 * a));
    public String getRoot2()
    if (getDescriminent() < 0.0 || a == 0.0)
    return "" + ((-b - Math.sqrt(-getDescriminent()))/(2 * a)) + " i";
    else
    return "" + ((-b - Math.sqrt(getDescriminent()))/(2 * a));
    public double getDescriminent()
    return (b*b - 4 * a * c);
    public void setA(double bValue)
    a = bValue;
    public void setB(double bValue)
    b = bValue;
    public void setC(double bValue)
    c = bValue;
    Thanks for the help
    Noel
    email: [email protected]

    Besides that, the code is broken. For instance
    return "" + ((-b - Math.sqrt(-getDescriminent()))/(2 * a)) + " i";should be
    return "" + (-b/(2*a)) + " " + (-Math.sqrt(-getDescriminent())/(2 * a)) + " i";
    to get correct answers... 1/2 * (-1-sqrt(3)) i (or approximately -1.36602540 i) is not a solution of x^2 + x + 1 = 0. Also, if a is small, it's better to use the formula x = 2*c / (-b +/- sqrt(b^2 - 4ac))

  • HELPP PLEASE i need help solving this algorithm please!!

    Read the following algorithm for the recursive procedure called Mystery.
    MYSTERY(soFar, toGo)
    length = LEN(toGo)
    IF length = 1 THEN
    PRINT soFar & toGo
    ELSE
    FOR i = 1 to length
    MYSTERY(soFar & MID$ (toGo, i, 1),LEFT$(toGo, i � 1)
    & RIGHT$(toGo, length � i))
    NEXT i
    ENDIF
    END of procedure
    Where:
    LEN(aSTRING) returns the number of characters in the string held in aString,
    MID$(aString, n,m) returns m characters of aString starting at the nth,
    LEFT$(aString, n) returns the first n characters of aString,
    RIGHT$(aString, n) returns the last n characters of aString,
    & joins two strings together (concatenation).
    (a) Give the output if the procedure is called by
    MYSTERY('' '', ''RED'')
    (b) The function is called with
    MYSTERY('' '', ''AB'')
    Write down all the instructions, including procedure calls, in the order in which they are
    executed. You must show the values of the variables in each instruction.

    I'd to ask your tutor or classmates for help with homework.
    I don't see any relation with Java by the way.

  • Youtube no sound while video plays. Sound in other software is good. I tried to deleted all advance setting in flash play in system preference and download latest adobe flash player and restart computer. no help! please help solve this issue.

    No sound in youtube while video plays.

    From the Safari menu bar, select
              Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data...
    and confirm. Close the window. Then select
               ▹ System Preferences… ▹ Flash Player ▹ Advanced ▹ Delete All...
    In the sheet that opens, check the box marked
              Delete All Site Data and Settings
    then click Delete Data. Close the preference pane. Test.

  • I need help solving Latest Flash Player upgrade crashing issues.

    I recently upgraded my flash player at Adobe reccomendation. Now it crashes all the time. I need help solving this issue. I currently have Flash Version 11.5.502.135. My old version never crashed, not even once. I would be fine uninstalling the new version and going back to the older one but i cant find it.

    Could you please create a crash report? The following page has more information: http://helpx.adobe.com/flash-player/kb/report-flash-player-crash.html
    You can install Flash Player 11.4.402.287 version.
    Thanks,
    Sunil

  • My 1st gen ipod touch has N/A in the WI-FI option can anyone tell me how to solve this issue please.

    My 1st gen ipod touch has N/A in the option menu for wireless, can anyone help solve this issue please???

    iOS: Wi-Fi or Bluetooth settings grayed out or dim
    One user reported that placing the iPod in the freezer fixed the problem.
    If not successful, an appointment at the Genius Bar of an Apple store is usually in order.
    Apple Retail Store - Genius Bar

  • Have just down loaded Yosemite over Mountain Lion, Indesign CS5 does not work ( Am dependant on it) although Bridge , Light Room and Elements operate OK How do I solve this rapidly. Can any one help on this issue. Thanks

    Have just down loaded Yosemite over Mountain Lion, Indesign CS5 does not work ( Am dependant on it) although Bridge , Light Room and Elements operate OK How do I solve this rapidly. Can any one help on this issue. Thanks

    Sorry to say it, but I think you can see from Bob's response that there's no way to solve this rapidly.
    Did you take an image of your Mountain Lion install before upgrading to Yosemite? Roll back to that. If you're not in the habit of taking a snapshot of your system before performing operating system upgrades - get in that habit. If you are dependent on anything at all on hour computer, having a reliable backup method in place is essential. If you don't have a Time Capsule, or some other way to run Time Machine onto a disk that's not in your computer, go set that up yesterday.
    If you can't just remove Yosemite and roll back to Mountain Lion for whatever reason, you can partition your drive so that you can install both Yosemite and Mountain Lion on the same drive, and then boot into Mountain Lion when you need to work in CS5. Or you can take your Mountain Lion disc (I assume you have one, no?) and then use it to create a virtual machine in something like VirtualBox to run Mountain Lion from inside Yosemite.

Maybe you are looking for

  • MMD Hard Drive issues

    I attempted to install a new PATA hard drive and was never able to get it to be recognized or mount, no matter I gave up on that and went back to my original configuration to find that my 3rd small drive was now unreadable. I erased that and remounte

  • Apple Preview, creating multiple page PDFs

    I often need to create multiple page PDF documents by using either existing images or by using a scanner. Is there an easy way to so simply choose multiple files in the finder and right-click "Create PDF from files"? We have: - Compress 2 items - Ren

  • Merge PDF in BIP standalone

    Dear Forum Users, Can you please have a look at the following situation; - There's is an existing PDF file in a document management system, which is accessible by an hyperlink like; http://www.localhost.nl/drawing.pdf - I have the location in my XML

  • XML to Internal tables

    Hi, Our scenairo is to retreive the data from XML file and convert it into Idoc for inbound processing. I need to get the data from xml to the internal tables so that i can convert them to idoc through Function Modules. My issue is XML file is not fi

  • Conversion of planned order to process order

    Hi, I am having 3 valid production versions for the same lot size selections. I have created one planned order in that I maintained one production version. While converting into process order it is not picking up the production version what I mention