How to fire JComboBox itemStateChanged event manually?

hello:
I want to know how to fire JComboBox itemStateChanged event manually.
thank you
-Daniel

Call setSelectedIndex or setSelectedItem.

Similar Messages

  • How to fire mouse wheel events to parent container?

    Hi,
    When I create a JPanel (let's say jParent) inside a JScrollPane and this JPanel is larger than the current viewport I can use my mouse wheel to scroll the JPanel's containt without coding anything about that.
    But if I add another JPanel-derived component (let's say jChild) to the first JPanel, mouse wheel events are not received by the first JPanel when the mouse is over the new added child JPanel.
    How can I forward child's mouse wheel events to the first JPanel?
    If I use:
    jChild.addMouseWheelListener(jParent)I must implement a mouseWheelMoved() method in jParent that requires some code to work while it was doing it byitself before...
    Thanks in advance for any help :-)
    Regards,
    Lara.

    you have a mouseWheelListener added to jChild?
    if so, in the mouseWheelMoved code include this line
    jParent.dispatchEvent(mouseWheelEvent);//or to the scrollpane

  • OT: Remind me, please, how to fire an onload event with javascript!

    How do I do this without screwing with the body tag?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================

    I just want to add a post in clarification -
    1. I was using EasyFaq (a very nice extension from
    ValleyWebDesigns) in a
    non-standard way. Had I used it out of the box, so to speak,
    I would not
    have had these problems.
    2. To reiterate, the problems I were trying to solve were, in
    no way,
    related to standard use of EasyFAQ.
    3. My problems were solved both by following the suggestions
    of Al Sparber,
    and with help from E. Michael Brandt.
    4. Indeed, I had some invalid code on the page, and it was
    the presence of
    that code that made things get a little cockeyed.
    The page, if you care to see it, is here -
    http://66.165.96.228/t_faq.php
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Murray *ACE*" <[email protected]> wrote
    in message
    news:enheq7$po6$[email protected]..
    > You should know by now that I practice safe diddling.
    >
    > --
    > Murray --- ICQ 71997575
    > Adobe Community Expert
    > (If you *MUST* email me, don't LAUGH when you do so!)
    > ==================
    >
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    > ==================
    >
    >
    > "Gary White" <[email protected]> wrote in message
    > news:[email protected]..
    >> On Wed, 3 Jan 2007 11:56:22 -0500, "Murray *ACE*"
    >> <[email protected]> wrote:
    >>
    >>>But I'm still diddling.... 8)
    >>
    >>
    >> Be sure to use protection!
    >>
    >> Gary
    >
    >

  • How to fire an onblur event for htmlb:inputfield ?

    Hi All,
    I have a problem in creating in ONBLUR..for input field.
    What i want is when i give input to the input it goes to DB and retriving some data  and visible to next Dropdown.
    For this if i give input to input field and press any key then it will goes to db and getting data.
    I am stricking over here .
    Please guide me for this.
    Thanks
    Nageswara.

    so what you need is a javscript function to get triggered onblur event and it should generate server event.
    check out the following code sample.
    <htmlb:inputField id         = "test"
                            alignment  = "LEFT"
                            size       = "10"
                            type       = "STRING" />
          <bsp:htmlbEvent id      = "myid"
                          onClick = "myonclick"
                          name    = "ValueChanged" />
            <script for="test" event=onblur type="text/javascript">
          ValueChanged();
          </SCRIPT>
    Regards
    Raja

  • JTree - How do I fire a valueChange Event from a keyPressed Event?

    Hi,
    I have been stumped trying to figure out how to fire a valueChange event in my JTree from a keyPressed event.
    When a user changes tree node using the mouse a valueChange event fires. In my program the valueChange executes some code that must be done. I want to get my JTree to work, so that if a user is nagivating the tree using the keyboard, the code is only executed if they press the enter key.
    Below is a little demo program of what I am attempting to accomplish. Any suggestions would be greating appriciated.
    Thanks,
    Corey
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class SimpleTreeDemo extends JFrame  {
      public SimpleTreeDemo() {
      public static void main(String args[]) {
        JFrame j = new SimpleTreeDemo();
        DefaultMutableTreeNode category = new DefaultMutableTreeNode("Top of JTree");
        DefaultMutableTreeNode leaf1 = new DefaultMutableTreeNode("leaf1");
        DefaultMutableTreeNode leaf2 = new DefaultMutableTreeNode("leaf2");
        category.add(leaf1); category.add(leaf2);
        final JTree jtree = new JTree(category);
        boolean bflag = false;
        jtree.addTreeSelectionListener(new TreeSelectionListener() {
             public void valueChanged(TreeSelectionEvent e) {
                  System.out.println("valueChanged");
                  if (bflag)
                       // Execute Code
        jtree.addKeyListener(new KeyListener() {
            public void keyTyped(KeyEvent ke) {
              System.out.println("keyTyped");
            public void keyPressed(KeyEvent ke) {
                 System.out.println("keyPressed");
                 if (ke.getKeyCode() == KeyEvent.VK_ENTER)
                      bflag = true;
                    // Fire valueChanged here!
            public void keyReleased(KeyEvent ke) {
                 System.out.println("keyReleased");}
        Container c = j.getContentPane();
        c.add(jtree);
        j.setSize(200,200);
        j.show();

    Try this, it works for me.
    // Tree Key Listener
          tree.addKeyListener(new java.awt.event.KeyAdapter() {
             public void keyPressed(KeyEvent e) {
                tree_KeyReleased(e);
    private void tree_KeyReleased(KeyEvent e) {
          try {
          int keyCode = e.getKeyCode();
          // Get the Tree Path
          TreePath selPath = tree.getSelectionPath();
          if (keyCode == e.VK_DELETE) { //KeyCode - 127
             removeSelectedNode(); // Remove the node
          else if (keyCode == e.VK_ADD) { // Key Code - 107
             tree.expandPath(selPath); // Expand the Node
          else if (keyCode == e.VK_SUBTRACT) { // Key Code 109
             tree.collapsePath(selPath); // Collapse the Node
          else if (keyCode == e.VK_ENTER) {
              // What Ever you want to do here
          else {
          } catch (NullPointerException ex) {
          //System.out.println("Null");
    [/code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to make jcombobox display all by itlself?

    Hello all -
    Is there a way to make a jcombobox object display its column of items implicitly?
    For example, suppose a program has a combobox filled up with names. And, suppose the first item says "toggle sort", which affects how the items are sorted in the combobox (eg, pressing it should cause the list to sort the displayed names based on first name, another press bases the sort on the last name...). The behavior I am aiming for is that when the user presses the "toggle sort" item, the combobox displays its items again awaiting further selection from the user (but not the first item). Know how to fire such an event?
    private void namesComboBoxActionPerformed(ActionEvent evt) {
       int selected = namesComboBox.getSelectedIndex();
       if (selected == 0) {
          // some code should result in the namesComboBox displaying its items again. What is it please?
    }

    Here is a simple code, I don't know if its the correct way to do this sort of thing but it works:
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Collections;
    import javax.swing.*;
    * Sorting Combobox....
    * @author talha
    public class ComboSort extends JFrame{
        ArrayList<ComboData> data;
        JComboBox combo;
        public ComboSort() {
            super("Combo Sorting");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            populateData();
            Collections.sort(data);
            // I don't know how much of the combobox model should be overridden!
            combo=new JComboBox(new DefaultComboBoxModel() {
                @Override
                public Object getElementAt(int index) {
                    return (index==0)?"Toggle Sort":data.get(index-1);
                @Override
                public int getSize() {
                    return data.size()+1;
                @Override
                public int getIndexOf(Object anObject) {
                    return (anObject instanceof String)?0:data.indexOf(anObject)+1;
            combo.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(combo.getSelectedIndex()==0){
                        ComboData.toggleSort();
                        Collections.sort(data);
                        //edited to make the pop up visible....
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                combo.setPopupVisible(true);
            combo.setRenderer(new DefaultListCellRenderer() {
                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    Component renderer=super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    if(value instanceof String){
                        renderer.setForeground(Color.BLUE);
                        renderer.setBackground(Color.YELLOW);
                    return renderer;
            // you can remove following....
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    combo.setSelectedIndex(0);
            getContentPane().setLayout(new FlowLayout());
            getContentPane().add(new JLabel("Heads of State:"));
            getContentPane().add(combo);
            setSize(300, 300);
            setLocationRelativeTo(null);
        private void populateData() {
            data=new ArrayList<ComboData>();
            data.add(new ComboData("Barak", "Obama"));
            data.add(new ComboData("Gordon", "Brown"));
            data.add(new ComboData("Nicolas", "Sarkozy"));
            data.add(new ComboData("Angela", "Merkel"));
            data.add(new ComboData("Wen", "Jiabao"));
            data.add(new ComboData("Taro", "Aso"));
            data.add(new ComboData("Manmohan", "Singh"));
            data.add(new ComboData("Asif", "Zardari"));
            data.add(new ComboData("Mahmoud", "Ahmedinejad"));
            data.add(new ComboData("Hugo", "Chavez"));
            data.add(new ComboData("Raul", "Castro"));
        public static void main(String args[]){
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new ComboSort().setVisible(true);
    class ComboData implements Comparable{
        String firstname;
        String lastname;
        static boolean sortFirstName;
        public ComboData(String firstname, String lastname) {
            this.firstname = firstname;
            this.lastname = lastname;
        @Override
        public String toString() {
            return firstname+" "+lastname;
        public static void toggleSort(){
            sortFirstName=!sortFirstName;
        public int compareTo(Object o) {
            ComboData other=(ComboData)o;
            if(sortFirstName)return firstname.compareTo(other.firstname);
            else return lastname.compareTo(other.lastname);
    }Thanks!
    Edit: Reread your original post and made few editions... but I still don't think that this is what you need (but now its much better) :-)
    Edited by: T.B.M on Apr 19, 2009 1:16 PM

  • How to fire event to generate insert message for the child objects?

    We are in process to integrate CRM On Demand and existing Microsoft SQL DB.
    We have the following problem:
    For ex., we have CRM Object_1 that already synchronized with the SQL DB. CRM also has independent Object_2 and its child Object_2.1
    We dicided that we want to connect the Object_2 as child to the Object_1.
    The question is how to fire event to generate insert message for the Object_2 and Object_2.1?
    What is the best technique? Is it possible to do it by workflow configuration or it needs to be done programmatically?
    Thanks,
    Dmitry
    Edited by: 955827 on Aug 29, 2012 11:57 AM

    Hi,
    integration events can be generated only via worklow. You will need to create separate workflows for each record type (regardless if it is child or parent) because a workflow for the parent record type will not trigger when a child record is created/ associated. Also, the association workflows will trigger only when the specific event occurs.
    There is not way to generate the integrtaion events programatically. They are generated by workflows and are read/ interpreted by a code extension.

  • How to fire an event dynamically in JSF Page

    Hi All
    How to fire an event dynamically in JSF Page?
    Thanks
    Sudhakar

    Hi,
    Thanks for the response. I mean to say, if I create the components dynamically then how can I fire events for those components.
    In otherwords,
    If I create the Button dynamically with particular ID being set to that component, then how can I call button action event when the button is clicked??
    Hope you understand
    What is the role of MethodBinding mechanism here??
    Thanks
    Sudhakar Chavali

  • How to fire table column model event?

    I found that the method to fire column changed event are:
    protected  void      fireColumnAdded(TableColumnModelEvent e)
              Notifies all listeners that have registered interest for notification on this event type.
    protected  void      fireColumnMarginChanged()
              Notifies all listeners that have registered interest for notification on this event type.
    protected  void      fireColumnMoved(TableColumnModelEvent e)
              Notifies all listeners that have registered interest for notification on this event type.
    protected  void      fireColumnRemoved(TableColumnModelEvent e)
              Notifies all listeners that have registered interest for notification on this event type.
    protected  void      fireColumnSelectionChanged(ListSelectionEvent e) They are declared as protected. How can I use them? I added a column to JTable and want to fire this event. I know I can use AbstractTableModel.fireTableStructureChanged() method, but it cost more time.
    Does anyone of you use these methods? How do you use it?
    thanks

    It's a limitation of the TableModelEvent design: you can only signal the entire structure changed (with fireTableStructureChanged), but not individual columns added or removed.
    A proper solution would extend TabelModelEvent with column added/removed events and extend JTable to handle those.
    Another solution is to let the TableModel define all possible columns in advance and hide the ones not wanted in the JTable until they are needed.
    A dirty solutions breaks the model/view separation where the model can access the TableColumnModel to add/remove columns when needed.

  • How to fire another event handler for postprocess stage

    Hi All,
    I have 3 custom event handlers for postprocess stage, for modify action on user object. The problem is tah only one event handler is executed - I use EntityManager API to modify user object. How to fire another event handlers? Do I have use UserManager API?
    best
    mp

    As Bikash stated, used a single event handler. You can put if statements in there to identity the operation, as well as if statements if the parameter is found i the list of attributes being modified. This way you will only perform the action when necessary.
    -Kevin

  • JDev 10.1.3 ADF: How to fire an event when clicking a Radio Button

    I have a <af:table> component with the following code for my radio button
    <af:tableSelectOne text="Select and"
    binding="#{backing_viewFees.tableSelectOne1}"
    id="tableSelectOne1"
    attributeChangeListener="#{backing_viewFees.tableSelectOne1_attributeChangeListener}"
    autoSubmit="false">
    When I click the radio button it does not fire up my event in my backing bean?

    Thank you for the suggestion...it does work and fires the event, but it is still not selecting the current record when I try to perform an Update or Delete.
    I had to modify your code a bit in order for it work in JDev 10...used the JUCtrlValueBindingRef instead of the FacesCtrlHierNodeBinding.
    Here is what my af:table tag looks like:
    <af:table value="#{bindings.FeesView1.collectionModel}"
    var="row" rows="#{bindings.Fees001View1.rangeSize}"
    first="#{bindings.FeesView1.rangeStart}"
    emptyText="#{bindings.FeesView1.viewable ? \'No rows yet.\' : \'Access Denied.\'}"
    selectionListener="#{backing_viewFees.tableSelectOne1_attributeChangeListener}"
    binding="#{backing_viewFees.table1}" id="table1">
    If I put back my 2 original attributes, then my Delete and Updates work.
    selectionState="#{bindings.FeesView1.collectionModel.selectedRow}"
    selectionListener="#{bindings.FeesView1.collectionModel.makeCurrent}"
    Here is my code in the backing bean:
    public void tableSelectOne1_attributeChangeListener(SelectionEvent selectionEvent) {
    JUCtrlValueBindingRef binding = (JUCtrlValueBindingRef)this.getTable1().getSelectedRowData();
    if (binding != null) {
    Row currentRow = binding.getRow();
    if (currentRow != null) {
    System.out.println(currentRow.getAttribute("CurrentRecordInd")); // this does print my selected value!!!!
    }

  • How to fire a window closing event, not clicking the X button of the UI

    I�ve an application that uses a WindowListener for the WindowClosing event of a JFrame. When the user presses CTRL-Q I needed to fire a windowClosing for that frame, in order to detect it and take some actions in the class referencig the JFrame (this class has the windowListener).
    setDefaultCloseOperation was not good for me, so i fire the windowClosing event with the following code:
    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        WindowEvent we = new WindowEvent(this,WindowEvent.WINDOW_CLOSING, null, 0, 0);
        this.getWindowListeners()[0].windowClosing(we);
    }Hope this is the right way to fire the event and this helps someone. If not please code a better way,
    Alonso

    Yes, that works and looks better:
    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                            
       this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    } "this" refers to the JFrame.

  • JComboBox Action Event problems

    I have a complex UI with which I am having action event issues. Basically, the panel displays info about an object, which can be selected from within the panel through a button/popup window mechanism. A JComboBox (#1) selection determines the contents of another JComboBox (#2) on the same panel. Currently an ActionEvent fires when the user makes a selection using #1 that updates #2. This fuctions correctly with repeated testing so long as a new object is not selected.
    When a new object is selected from within this panel this ActionEvent no longer fires. JComboBox #1 will be updated correctly and #2 will reflect the initial selection in #1, but user selections in #1 will not fire the ActionEvent and thus #2 is never updated.
    Any help is appreciated. I feel like I'm missing something basic here, but I've stared at it for long enough...

    By the way, the workaround is to use the ItemListener as the ItemStateChanged Event is fired reliably.

  • How to store JcomboBox n textfield into textfile? Urgent!!!

    How to store JcomboBox n textfield into textfile?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.text.DecimalFormat;
    import java.io.*;
    public class RecordMenu extends JPanel implements ActionListener {
        private JComboBox monthSelection;
        private JButton buttonOk;
        double amtToTrack;
        private JTextField amtField;
        private static final String[] Months =
         new String[] {
             "January",
             "February",
             "March",
             "April",
             "May",
             "June",
             "July",
             "August",
             "September",
             "October",
             "November",
             "December"
        public RecordMenu() {      
            JPanel mainPanel = new JPanel();
            mainPanel.setLayout(new GridLayout(4,2));
            mainPanel.setBorder(new TitledBorder("Record Expenses"));
            JLabel monthLabel = new JLabel("Select month");      
            monthSelection = new JComboBox(Months);      
            monthSelection.addActionListener(this);
            JLabel label2 = new JLabel("Amount to track:");       
            JTextField amtField = new JTextField(5);
            amtField.addActionListener(this);
            JLabel nothing1 = new JLabel("nothing");
            nothing1.setVisible(false);
            JLabel nothing2 = new JLabel("nothing");
            nothing2.setVisible(false);
            JLabel nothing3 = new JLabel("nothing");
            nothing3.setVisible(false);
            JLabel nothing4 = new JLabel("nothing");
            nothing4.setVisible(false);
            JLabel nothing5 = new JLabel("nothing");
            nothing5.setVisible(false);
            JLabel nothing6 = new JLabel("nothing");
            nothing6.setVisible(false);
            JLabel nothing7 = new JLabel("nothing");
            nothing7.setVisible(false);
            JLabel nothing8 = new JLabel("nothing");
            nothing8.setVisible(false);
            mainPanel.add(monthLabel);
            mainPanel.add(monthSelection);
            mainPanel.add(nothing1); 
            mainPanel.add(label2);
            mainPanel.add(amtField);
            mainPanel.add(nothing2);
            mainPanel.add(nothing3);
            mainPanel.add(nothing4);
            mainPanel.add(nothing5);
            mainPanel.add(nothing6);
            mainPanel.add(nothing7);
            JButton buttonOk = new JButton("OK");     
            buttonOk.addActionListener(this);
            mainPanel.add(buttonOk);
            add(mainPanel);      
            setSize(400,300);
            setVisible(true);
        public void actionPerformed(ActionEvent e) {                
             if (e.getSource() == buttonOk) {
             double amtToTrack = 0.0;
             try {
             if (!amtField.getText().equals(""))
                   amtToTrack = Double.parseDouble(amtField.getText());
             catch (NumberFormatException numberFormatException) {
                  JOptionPane.showMessageDialog(this, "You must enter numbers","Invalid Number Format", JOptionPane.ERROR_MESSAGE);
                         try{               
                             BufferedWriter out = new BufferedWriter(new FileWriter("mySaved.txt",true));
                             out.write("For Month "+Months);
                             out.newLine();
                             if (!amtField.getText().equals("")) {     
                             amtToTrack = Double.parseDouble(amtField.getText());
                             out.write("Amount to track = "+amtToTrack);   
                             out.newLine();     
                             out.close();
                             JOptionPane.showMessageDialog(this, "Saved!");                         
                            catch(IOException ex) {   
                            ex.printStackTrace(System.err);
        public static void main(String[] args) {
            JPanel p = new RecordMenu();
            JFrame f = new JFrame();
            Container c = f.getContentPane();
            c.add(p);
            f.pack();
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              f.setVisible(true);
    }

    i had save e month at mySavedTotal
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.text.DecimalFormat;
    import java.io.*;
    public class RecordMenu extends JPanel implements ActionListener {
        private JComboBox monthSelection;
        private JButton buttonOk;
        double amtToTrack;
        private JTextField amtField;
        private static final String[] Months =
         new String[] {
             "January",
             "February",
             "March",
             "April",
             "May",
             "June",
             "July",
             "August",
             "September",
             "October",
             "November",
             "December"
        public RecordMenu() {      
            JPanel mainPanel = new JPanel();
            mainPanel.setLayout(new GridLayout(4,2));
            mainPanel.setBorder(new TitledBorder("Record Expenses"));
            JLabel monthLabel = new JLabel("Select month");      
            monthSelection = new JComboBox(Months);      
            monthSelection.addActionListener(this);
            JLabel label2 = new JLabel("Amount to track:");       
            amtField = new JTextField(5);
            amtField.addActionListener(this);
            JLabel nothing1 = new JLabel("nothing");
            nothing1.setVisible(false);
            JLabel nothing2 = new JLabel("nothing");
            nothing2.setVisible(false);
            JLabel nothing3 = new JLabel("nothing");
            nothing3.setVisible(false);
            JLabel nothing4 = new JLabel("nothing");
            nothing4.setVisible(false);
            JLabel nothing5 = new JLabel("nothing");
            nothing5.setVisible(false);
            JLabel nothing6 = new JLabel("nothing");
            nothing6.setVisible(false);
            JLabel nothing7 = new JLabel("nothing");
            nothing7.setVisible(false);
            JLabel nothing8 = new JLabel("nothing");
            nothing8.setVisible(false);
            mainPanel.add(monthLabel);
            mainPanel.add(monthSelection);
            mainPanel.add(nothing1); 
            mainPanel.add(label2);
            mainPanel.add(amtField);
            mainPanel.add(nothing2);
            mainPanel.add(nothing3);
            mainPanel.add(nothing4);
            mainPanel.add(nothing5);
            mainPanel.add(nothing6);
            mainPanel.add(nothing7);
            buttonOk = new JButton("OK");     
            buttonOk.addActionListener(this);
            mainPanel.add(buttonOk);
            add(mainPanel);      
            setSize(400,300);
            setVisible(true);
        public void actionPerformed(ActionEvent e) {                
             if (e.getSource() == buttonOk) {
             double amtToTrack = 0.0;
             try {
             if (!amtField.getText().equals(""))
                   amtToTrack = Double.parseDouble(amtField.getText());
             catch (NumberFormatException numberFormatException) {
                  JOptionPane.showMessageDialog(this, "You must enter numbers","Invalid Number Format", JOptionPane.ERROR_MESSAGE);
                         try{               
                             BufferedWriter out = new BufferedWriter(new FileWriter("mySavedTotal.txt",true));
                             out.write("For Month "+monthSelection.getSelectedItem());
                             out.newLine();
                             if (!amtField.getText().equals("")) {     
                             amtToTrack = Double.parseDouble(amtField.getText());
                             out.write("Amount to track = "+amtToTrack);   
                             out.newLine();     
                             out.close();
                             JOptionPane.showMessageDialog(this, "Saved!");
                             JPanel p = new CheckBox();         
                             JFrame f = new JFrame();         
                             Container c = f.getContentPane();         
                             c.add(p);         
                             f.pack();         
                             f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);         
                             f.setVisible(true);                              
                            catch(IOException ex) {   
                            ex.printStackTrace(System.err);
        public static void main(String[] args) {
            JPanel p = new RecordMenu();
            JFrame f = new JFrame();
            Container c = f.getContentPane();
            c.add(p);
            f.pack();
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              f.setVisible(true);
    }then i save data from other file in mySavedTotal again
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.text.DecimalFormat;
    import java.io.*;
    public class CheckBox extends JPanel implements ItemListener, ActionListener {
         private JPanel checkPanel, buttonPanel;
         private JCheckBox transport, bills, food, gifts, leisure, others;
         private JTextField transportField, billsField, foodField, giftsField,leisureField,
                        othersField, totalField;
         double transportAmt, billsAmt, foodAmt, giftsAmt, leisureAmt, othersAmt, totalAmt;
         private JButton buttonTotal, saveButton, dontSaveButton;
         private JLabel showTotal;
         public CheckBox() {          
              //create a panel for diaplaying the checkboxs and buttons
              checkPanel = new JPanel();
              checkPanel.setLayout(new GridLayout(7,3));
              //Create the check boxes.
              transport = new JCheckBox("Transport");
              transport.setSelected(false);
              transport.setBounds(10,30,80,30);
              transportField = new JTextField();
              transportField.setEditable(false);
              transportField.setBounds(100,35,45,20);
              bills = new JCheckBox("Bills");
              bills.setSelected(false);
              bills.setBounds(10,60,80,30);
              billsField = new JTextField(5);
              billsField.setEditable(false);
              billsField.setBounds(100,65,45,20);
              food = new JCheckBox("Food");
              food.setSelected(false);
              food.setBounds(10,90,80,30);
              foodField = new JTextField(5);
              foodField.setEditable(false);
              foodField.setBounds(100,95,45,20);
              gifts = new JCheckBox("Gifts");
              gifts.setSelected(false);
              gifts.setBounds(200,30,80,30);
              giftsField = new JTextField(5);
              giftsField.setEditable(false);
              giftsField.setBounds(300,35,45,20);
              leisure = new JCheckBox("Leisure");
              leisure.setSelected(false);
              leisure.setBounds(200,60,80,30);
              leisureField = new JTextField(5);
              leisureField.setEditable(false);
              leisureField.setBounds(300,65,45,20);
              others = new JCheckBox("Others");
              others.setSelected(false);
              others.setBounds(200,90,80,30);
              othersField = new JTextField(5);
              othersField.setEditable(false);
              othersField.setBounds(300,95,45,20);
              JLabel nothing1 = new JLabel("nothing");
            nothing1.setVisible(false);
            JLabel nothing2 = new JLabel("nothing");
            nothing2.setVisible(false);
            JLabel nothing3 = new JLabel("nothing");
            nothing3.setVisible(false);
            JLabel nothing4 = new JLabel("nothing");
            nothing4.setVisible(false);
            JLabel nothing5 = new JLabel("nothing");
            nothing5.setVisible(false);
            JLabel nothing6 = new JLabel("nothing");
            nothing6.setVisible(false);
            JLabel nothing7 = new JLabel("nothing");
            nothing7.setVisible(false);
            JLabel nothing8 = new JLabel("nothing");
            nothing8.setVisible(false);
            JLabel nothing9 = new JLabel("nothing");
            nothing9.setVisible(false);
            JLabel nothing10 = new JLabel("nothing");
            nothing10.setVisible(false);
            JLabel nothing11 = new JLabel("nothing");
            nothing11.setVisible(false);
              //Register a listener for the check boxes.
              transport.addItemListener(this);
              bills.addItemListener(this);
              food.addItemListener(this);
              gifts.addItemListener(this);
              leisure.addItemListener(this);
              others.addItemListener(this);
              transportField.addActionListener(this);
              billsField.addActionListener(this);
              foodField.addActionListener(this);
              giftsField.addActionListener(this);
              leisureField.addActionListener(this);
              othersField.addActionListener(this);
              checkPanel.add(transport);
              checkPanel.add(transportField);
              checkPanel.add(bills);
              checkPanel.add(billsField);
              checkPanel.add(food);
              checkPanel.add(foodField);
              checkPanel.add(gifts);
              checkPanel.add(giftsField);
              checkPanel.add(leisure);
              checkPanel.add(leisureField);
              checkPanel.add(others);
              checkPanel.add(othersField);
              checkPanel.setBounds(1,1,390,180);
              checkPanel.setBorder(new TitledBorder("Check the amount you want to track"));
              buttonTotal = new JButton("Calculate Total");
              buttonTotal.setBounds(150,140,130,30);
              buttonTotal.addActionListener(this);
              showTotal = new JLabel(" = __");
              showTotal.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
              showTotal.setBounds(290,140,100,30);
              checkPanel.add(nothing1);
              checkPanel.add(nothing2);
              checkPanel.add(nothing3);
              checkPanel.add(nothing4);
              checkPanel.add(nothing5);
              checkPanel.add(nothing6);
              checkPanel.add(buttonTotal);
              checkPanel.add(showTotal);
              checkPanel.add(nothing7);
              checkPanel.add(nothing8);
              checkPanel.add(nothing9);
              checkPanel.add(nothing10);
              checkPanel.add(nothing11);
              saveButton = new JButton("Save");
              saveButton.setBounds(90,190,100,30);
              saveButton.addActionListener(this);
              dontSaveButton = new JButton("Don't Save");
              dontSaveButton.setBounds(200,190,100,30);
              dontSaveButton.addActionListener(this);
              checkPanel.add(saveButton);
             checkPanel.add(dontSaveButton);
            add(checkPanel);       
              setSize(400,260);
              setVisible(true);
              /** Listens to the check boxes. */
              public void itemStateChanged(ItemEvent e) {
              if (e.getSource() == transport)
              if (e.getStateChange() == ItemEvent.SELECTED)          
              transportField.setEditable(true);
              else
              transportField.setEditable(false);
              if (e.getSource() == bills)
              if (e.getStateChange() == ItemEvent.SELECTED)
              billsField.setEditable(true);
              else
              billsField.setEditable(false);
              if (e.getSource() == food)
              if (e.getStateChange() == ItemEvent.SELECTED)
              foodField.setEditable(true);
              else
              foodField.setEditable(false);
              if (e.getSource() == gifts)
              if (e.getStateChange() == ItemEvent.SELECTED)
              giftsField.setEditable(true);
              else
              giftsField.setEditable(false);
              if (e.getSource() == leisure)
              if (e.getStateChange() == ItemEvent.SELECTED)
              leisureField.setEditable(true);
              else
              leisureField.setEditable(false);
              if (e.getSource() == others)
              if (e.getStateChange() == ItemEvent.SELECTED)
              othersField.setEditable(true);
              else
              othersField.setEditable(false);
              public void actionPerformed(ActionEvent event) {
              try {     
             if (event.getSource() == buttonTotal) {
                  double transportAmt=0.0, billsAmt=0.0, foodAmt=0.0, giftsAmt=0.0,leisureAmt=0.0, othersAmt=0.0, totalAmt=0.0;
                   if (!transportField.getText().equals(""))
                   transportAmt = Double.parseDouble(transportField.getText());
                   if(!billsField.getText().equals(""))
                   billsAmt = Double.parseDouble(billsField.getText());
                   if(!foodField.getText().equals(""))
                   foodAmt = Double.parseDouble(foodField.getText());
                   if(!giftsField.getText().equals(""))
                   giftsAmt = Double.parseDouble(giftsField.getText());
                   if(!leisureField.getText().equals(""))
                   leisureAmt = Double.parseDouble(leisureField.getText());
                   if(!othersField.getText().equals(""))
                   othersAmt = Double.parseDouble(othersField.getText());
                   totalAmt = transportAmt + billsAmt + foodAmt + giftsAmt + leisureAmt + othersAmt;
                   showTotal.setText("= $" + totalAmt);
              catch (NumberFormatException numberFormatException ) {
                        JOptionPane.showMessageDialog(this, "You must enter numbers!","Invalid Number Format", JOptionPane.ERROR_MESSAGE);
                   if (event.getSource() == dontSaveButton) {
                        System.exit(0);
                        if(event.getSource() ==saveButton){     
                        double transportAmt=0.0, billsAmt=0.0, foodAmt=0.0, giftsAmt=0.0,leisureAmt=0.0, othersAmt=0.0, totalAmt=0.0;      
                        try{
                             BufferedWriter out = new BufferedWriter(new FileWriter("mySavedTotal.txt",true));
                             if (!transportField.getText().equals("")) {     
                             transportAmt = Double.parseDouble(transportField.getText());
                             out.write("Transport = "+transportAmt);   
                             out.newLine();     
                             if(!billsField.getText().equals("")) {     
                             billsAmt = Double.parseDouble(billsField.getText());     
                             out.write("Bills = "+billsAmt);     
                             out.newLine();     
                             if(!foodField.getText().equals("")) {     
                             foodAmt = Double.parseDouble(foodField.getText());     
                             out.write("Food = "+foodAmt);     
                             out.newLine();     
                             if(!giftsField.getText().equals("")){     
                             giftsAmt = Double.parseDouble(giftsField.getText());     
                             out.write("Gifts = "+giftsAmt);     
                             out.newLine();
                             if(!leisureField.getText().equals("")){     
                             leisureAmt = Double.parseDouble(leisureField.getText());     
                             out.write("Leisure = "+leisureAmt);     
                             out.newLine();     
                             if(!othersField.getText().equals("")) {     
                             othersAmt = Double.parseDouble(othersField.getText());     
                             out.write("Others = "+othersAmt);     
                             out.newLine();     
                             out.write("Total amount "+showTotal.getText());
                        out.newLine();                              
                             out.close();
                             JOptionPane.showMessageDialog(this, "Everything is saved!");
                             catch(IOException e){
                                  JOptionPane.showMessageDialog(this, "You must enter integers!","Invalid Number Format",JOptionPane.ERROR_MESSAGE);
                        public static void main(String[] args) {                         
                             JPanel p = new CheckBox();
                        JFrame f = new JFrame();
                        Container c = f.getContentPane();
                        c.add(p);
                        f.pack();
                        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                          f.setVisible(true);
                        }urgent... how to rerieve saved data? i got try b4 but didnt work out

  • How to perform an autocheck event when the field changes in ALV

    Hi everybody,
    how can I build an event or something which would make my 'wa_fieldcat-checkbox' set to 'X' (auto checked) everytime an editable field in the ALV is changed manually by the user?
    I want to perform this task in order to avoid asking the user to manually check the "check box" field everytime wants to make a change, since after the user's changes in the ALV I want to sort the itab with the check box column of the edited items.
    Thanks,
    Denis M

    Hi Denis,
    For ALV a FM REUSE_ALV_GRID_DISPLAY is available.
    The FM, has events as importing option.
    SLIS_T_EVENT
    EVENT - Basically this is the FM to handle Event's. When the user needs to do
    some event operation like when double clicking the a particular field we need to
    perform some operation.   These events are captured by this FM.
    slis_ev_data_changed -- To capture user command
    slis_ev_user_command -- To capture data changed.
    Also please refer the below link in scn. This shows sample code to capture ALV grid data changed.
    http://scn.sap.com/thread/261210
    Hope this will solve the problem.
    Thanks,
    Soundarya.

Maybe you are looking for

  • How can I create a new ring tone for my iPhone 4?

    How can I create a new ring tone for my iPhone 4? I followed the Garage Band process and ended up with the ring tone I want as a AAC audio file. It got stored in my iTunes a a song rather than a ring tone. How do I make it a ring tone vs. a song? I t

  • Is it possible to install a SSD in a MacBook?

    Is it possible to install a SSD in a MacBook? Saw some posts on google re: a Pro, but I use a MacBook for live performance and could really use the reliability of a SSD. Where to purchase, and how easy is an install?

  • Images not exporting to Ebook (for Kindle) correctly

    Using export to kindle plugin, on mac OS 10.6.8, InDesign CS5 When I export to Kindle (from the Book panel) using the following settings: (Options selected: Images > Copy Images > Optimized > Formatted > Image Conversion > Automatic) and preview on t

  • Target disk mode only shows bootcamp partition

    My mid 2006 MBP doesn't boot anymore, I am getting the gray screen with the rotating wheel. When trying to boot in target disk mode and connect it to my iMac only the bootcamp partition is mounting, but not the Macintosh HD, I could like to make a ba

  • Can access Yahoo, but can't open Yahoo Mail in Firefox. Can on Internet explorer.

    Can access Yahoo, but Can't open Yahoo Mail in Firefox. Can open Yahoo Mail on Internet Explorer. Checked Password.