Undo selection in JComboBox

Hi,
How can i add an undo selection functionality in a jComboBox? I know how it works in textcomponents and buttons but i have a problem with jComboBoxs.
Thnx

Hi,
How can i add an undo selection functionality in a
jComboBox? I know how it works in textcomponents and
buttons but i have a problem with jComboBoxs.
ThnxHi,
I won't claim to be an expert in the inner workings of the JComboBox class however from my experience, the way you would implement an undo functionality, at least the way I would do it, would be to implement an ordered collection (List or Stack or Queue, obviously not Set) to store something to remember the selection by...if the actual actual list contents can change dramatically or if the JComboBox is 'editable', then I would suggest storing objects.
Since Java stores objects as references rather than deep copying to create whole object instances, you would not have to worry about a whole ton of memory usage since only 1 copy of every object would ever be created.
Later, when the user invoked "Undo", if the object in question was the combo box, then you would just go to the last item in the list and set the selected index or value (depending on what you saved) to the value in the collection.
I don't have details or much code because I'm on my lunch break at work and don't work with java at my job, but try to come up with it on your own now and if you still can't do it, respond and I'll try to write something when I'm at home. Good Luck!

Similar Messages

  • Undo selection JComboBox

    Hi,
    How can i add an undo selection functionality in a jComboBox? I know how it works in textcomponents and buttons but i have a problem with jComboBoxs.
    Thnx

    Hi,
    How can i add an undo selection functionality in a
    jComboBox? I know how it works in textcomponents and
    buttons but i have a problem with jComboBoxs.
    ThnxHi,
    I won't claim to be an expert in the inner workings of the JComboBox class however from my experience, the way you would implement an undo functionality, at least the way I would do it, would be to implement an ordered collection (List or Stack or Queue, obviously not Set) to store something to remember the selection by...if the actual actual list contents can change dramatically or if the JComboBox is 'editable', then I would suggest storing objects.
    Since Java stores objects as references rather than deep copying to create whole object instances, you would not have to worry about a whole ton of memory usage since only 1 copy of every object would ever be created.
    Later, when the user invoked "Undo", if the object in question was the combo box, then you would just go to the last item in the list and set the selected index or value (depending on what you saved) to the value in the collection.
    I don't have details or much code because I'm on my lunch break at work and don't work with java at my job, but try to come up with it on your own now and if you still can't do it, respond and I'll try to write something when I'm at home. Good Luck!

  • How to make selection on JComboBox.

    Dear all,
    I want to make condition on basis of selection of JComboBox. Any one have code of such scenrio.
    Thanks in advance.

    Any one have code of such scenrio.Sun does.
    {color:#0000ff}http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html#getSelectedIndex()
    http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html#getSelectedItem()
    http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
    {color}
    db

  • Multiple selection in JComboBox

    Hi, Folks!
    I want to make my JComboBox to be multiple selected because there is a method called "getSelectedObjects()", but I don't know how to do it.
    Can anyone help me figure out how to do this?
    You help is much appreciated!
    Qun He

    Thanks a lot!
    Qun
    JComboBoxes can't have multiple selections. If you
    read the API documentation for
    JComboBox.getSelectedObjects() it says "Returns an
    array containing the selected item." The only reason
    the method is implemented is because JComboBox
    implements the ItemSelectable interface.

  • Select item JComboBox

    I have 2 JComboBoxes.
    The first contains: "all", x rows (query from a db)
    The second: "all sectors", y rows (query from a db)
    When i select one item from the first combo, the second hasd to start with "all sectors" + the rows that are queried from the db with the selected item from the first as parameter. That's not a problem.
    The problem appears when its done the other way around: when i select an item from the second combo, then has to appear in the first combo the corresponding item. but the second combo is filled up with only the rows that are queried from the db with the selected item from the first as parameter and so i always lose the item i selected in the second combo.
    can anyone help me plz?
    greetz
    hysterio
    ps. can i easily sort the items in a combo in alfabetic order?

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test2 extends JFrame {
      UserData[] userData = {new UserData("Ignatz","Renitskiwitz",1),
                             new UserData("John","Doe",37),
                             new UserData("Mary","Snow",96)};
      public Test2() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        JComboBox jcb = new JComboBox(userData);
        content.add(jcb, BorderLayout.NORTH);
        jcb.addItemListener(new ItemListener() {
          public void itemStateChanged(ItemEvent ie) {
            if (ie.getStateChange()!=ItemEvent.SELECTED) return;
            System.out.println("You picked user id "+((UserData)ie.getItem()).getID());
        setSize(300,300);
      public static void main(String[] args) { new Test2().setVisible(true); }
    class UserData {
      String fn, ln;
      int id;
      public UserData(String fn, String ln, int id) {
        this.fn=fn;
        this.ln=ln;
        this.id=id;
      public String toString() { return fn+" "+ln; }
      public int getID() { return id; }
    }

  • JAWS and Selection Events - JComboBox, JTabbedPane

    Hi,
    I am adding accessibility to one of our Products for a client that has employed a blind person. I am having trouble with JAWS reading items in JComboBoxes and items in JTabbedPanes.
    If I start JAWS then our application which runs in a browser as an applet, JAWS will read the label for the ComboBox when it is focussed, then read the Item name and which element of the total elements it is. eg. "Combo Box closed, Elephant 1 of 20". If I then try and change the selected item in the combo box JAWS will not read any of the selection changes. These results are the same with Java Ferret, it does not read any of the selection changes.
    Now the interesting part, if I start my applet and have it loaded and THEN start JAWS or Java Ferret, they will read the menu items as the selection changes. This problem is exactly the same for changing tabs in a JTabbedPane, JAWS will only read the Tab names if it is started after the Applet.
    If anyone can help with this problem it would be greatly appreciated.
    Thanks,
    Greg

    Hi,
    I am adding accessibility to one of our Products for a client that has employed a blind person. I am having trouble with JAWS reading items in JComboBoxes and items in JTabbedPanes.
    If I start JAWS then our application which runs in a browser as an applet, JAWS will read the label for the ComboBox when it is focussed, then read the Item name and which element of the total elements it is. eg. "Combo Box closed, Elephant 1 of 20". If I then try and change the selected item in the combo box JAWS will not read any of the selection changes. These results are the same with Java Ferret, it does not read any of the selection changes.
    Now the interesting part, if I start my applet and have it loaded and THEN start JAWS or Java Ferret, they will read the menu items as the selection changes. This problem is exactly the same for changing tabs in a JTabbedPane, JAWS will only read the Tab names if it is started after the Applet.
    If anyone can help with this problem it would be greatly appreciated.
    Thanks,
    Greg

  • How do I undo selecting do not save password?

    The first time I logged into my hotmail account Firefox asked the question - did I want Firefox to remember my password? I selected never. Now I wish to undo that selection and select remember. I went to the tools and cleared out my email address, reopened it to try to select remember. That did not work.

    If you select never then you create an exception that you have to remove.
    Remove the site from the exceptions: Tools > Options > Security: Passwords: Exceptions
    * [[Remembering passwords]]

  • How to undo "select distinct" in OBIEE

    Hello guys
    I found that pretty much in all the reports that we created in OBIEE, the presentation service would generate SQL that starts with "select distinct" when I view the query log..
    I'd like to know what configuration in the Admin Tool or presentation service is controlling this behavior of OBIEE. For some reason as I am tuning the performance by running the same query in DB, the same query without "distinct" can go so much faster than the original one from OBIEE.. So I'd like to configure my RPD so that certain reports will not have "select distinct". I know that by default, the BI server will always generate a "distinct", but is there a way to override this default, if not, what might be some performance tuning tactics I can use?
    Any thoughts?
    Thanks
    Edited by: user7276913 on Oct 27, 2009 8:20 PM

    BenS wrote:
    Two issues with this that I encountere:
    When I selected the first suggested option at the Physical Layer for the database, I found the "DISTINCT SUPPORTED" option. There were two columns checked: Value and Default. I was able to unselect Value but not Default.
    (1) What is the difference between Value and Default?
    (2) If I only unselect Value will it stop Answers from adding the DISTINCT to every query created?
    Second, when I selected the source from the business model mapping, it already did not have the DISTINCT box checked. Therefore, I could not limit this at the Logical layer as I would have preferred.
    If you could help me understand the first option it may clarify how to implement option # 2.
    Thanks...1) the defaults are stored in an .ini file and serve the purpose of defining the defaults when you hit the 'revert to default' button.
    If you unselect value, you are telling OBIEE that the database for which you are changing these options does not support the distinct clause, I doubt you wish to do this across the entire application.
    I think you will find that OBIEE applies the distinct :
    1) when the LTS has distinct ticked.
    2) When the column in question is not part of a dimension hierachy key (if it is, your telling the OBIEE server these should be unique, so wont issue the distinct)
    or
    3) the column forms part of a key in either logical BMM layer or as part of a physical key.
    adding the column to a Dim Hierachy wont be an option in most cases, you could try playing with just setting this column as a key on the BMM layer or Physical layer , and let us know if this helps.

  • JComboBox event notification when select first entry in pop-up menu JDK 6

    I recently began testing a Java GUI, I originally developed with JDK 1.5.0_11, with JDK 1.6.0_3. I have used the JComboBox in several applications developed using JDK 1.3.x and 1.4.x over the years. In every one of these earlier JDKs the JComboBox widgets all behaved the same. When you select the JComboBox widget, the pop-up menu appears and you can select any of the items from the menu list. Having made the selection with either a mouse click or a key press, an event notification is sent. Typically, an ActionEvent as well as either a mouse click event or a keypressed event may be sent. When testing with 1.6.0_x versions of the JDK and JRE, I can't account for any event notification being sent when selecting the first item at the top of the pop-up menu as the initial selection. If I select some other item on the list and then the first item, it works as it is supposed to work, but only after selecting another item first.
    I've placed the JComboBox in a JDialog and a JPanel. There are NO AWT widgets in any containers of the application. The same behavior seems to exist regardless of what other containing Swing component I place the JComboBox in. I'm running these applications on Windows XP, service pack 2. The system is an AMD 64 bit dual processor with 4Gb of RAM. The essential code follows:
    private JComboBox getJcboAlias()
        /* Note here that I am using a defaultComboModel as I have always done */
       jcboAliases = new JComboBox(urls);
       *jcboAliases.setEditable(false);*                               // Note here that the JComboBox is NOT editable
       jcboAliases.addActionListener(new ActionListener()   // ActionListener only receives a notification if the second or
       {                                                                            // another item in the pop-menu list is selected...but never the
          public void actionPerformed(ActionEvent ae)           // first item in the list
             String s = (String) jcboAliases.getSelectedItem();
             for (int i = 0; i < connections.size(); i++)
                conAlias = (String[]) connections.get(i);
                if (s.equals(conAlias))
    isSelected = true;
    break;
    jlblName.setVisible(true);
    jlblAlias.setVisible(true);
    jlblUID.setVisible(true);
    jlblPWD.setVisible(true);
    jtxtName.setText(conAlias[0]);
    jtxtName.setVisible(true);
    jtxtAddress.setText(conAlias[1]);
    jtxtAddress.setVisible(true);
    jtxtUID.setText(conAlias[2]);
    jtxtUID.setVisible(true);
    jtxtPWD.setVisible(true);
    jtxtPWD.setText("");
    jtxtPWD.requestFocus();
    return jcboAliases;
    }    I'm using a non-editable JComboBox because there is a pop-up menu with this and not with the JList widget.  JComboBox behaves more like the JList MicroSoft counterpart.  Another code snippet follows in which the JComboBox is editable.  The same errant behavior occurs when selecting the first item from the pop-up menu: private JComboBox getJcboPCMember()
    jcboPCMember = new JComboBox(PCViewerCustom.getCurrentMembers());
    jcboPCMember.setBounds(250, 103, 180, 20);
    jcboPCMember.setToolTipText("PATHCHECK(ER) member name - Example: CKPPTHCK");
    jcboPCMember.setSelectedIndex(Integer.valueOf(PCViewerCustom.getCurrentHost(3)));
    jcboPCMember.setEditable(true); // Note here that this JComboBox IS editable
    jcboPCMember.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    if (ae.getActionCommand().equals("comboBoxEdited"))
    boolean copy = false;
    for (int i = 0; i < jcboPCMember.getItemCount(); i++)
    if (jcboPCMember.getSelectedItem().equals(jcboPCMember.getItemAt(i)))
    copy = true;
    break;
    if (!copy)
    if (jcboPCMember.getItemCount() > 0)
    if (jcboPCMember.getItemAt(0).equals("No Entries"))
    jcboPCMember.removeItem("");
    jcboPCMember.removeItem("No Entries");
    jcboPCMember.insertItemAt((String) jcboPCMember.getSelectedItem(), 0);
    else
    jcboPCMember.removeItem("");
    jcboPCMember.addItem((String) jcboPCMember.getSelectedItem());
    enableJbtnOK();
    else
    if (jcboPCMember.getSelectedIndex() >= 0)
    PCViewerCustom.setCurrentHost(3, Integer.toString(jcboPCMember.getSelectedIndex()));
    enableJbtnOK();
    else
    JOptionPane.showMessageDialog(null, "Name not selected", "Error", JOptionPane.ERROR_MESSAGE);
    return jcboPCMember;
         I am able to add a new entry to the JComboBox, however, I am still unable to select the first item from the pop-up menu and fire any kind of notification event.  I have not seen this behavior before in any earlier versions of the JDK and it's playing havoc with my ability to deploy the application into a JDK or JRE V6 environment, without adding a bunch of additional code to pre-select the first item on the list, which pretty much defeats the purpose of the JComboBox.  I'll be the first to admit I've done something wrong, but i've built a number of test scenarios now on two systems runing Win XP SP2 and I get the same errant behavior.  I've also added in event listeners for a MouseListerner, a KeyListener and an ItemListener.  Still no event notification on this first item in the list.  Again, however, if I select one of the other items from the pop-up menu list and then select the first item, all is well.  Imagine selling that method of operation to a user....  It occurs to me that this must be a bug in the V6 JComboBox.  I wanted to post this here first, however, in order to determine if this is, in fact, a bug - in other words, am I the only one seeing this, or is this a more widespread issue?  Any assistance in making this determination is greatly appreciated.
    David Baker
    Edited by: Galstuk on Nov 27, 2007 12:21 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    here is the other file as well:
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Attachments:
    VI2.vi ‏5 KB

  • JComboBox remaining selected in JTable

    I have yet to figure out how to fix this problem. I have a JTable that is refreshed often with new data from a database (Next and Previous). If I select a JComboBox in the JTable, when I select Next or Previous the box remains selected and the value currently selected remains in there despite the new values from the DB. I know that the JComboBox refreshes correctly unless it is selected.
    How do you reset a JComboBox in a JTable so that you can update the JTable with the correct information without having to select something else?
    Note: When I hit the last, sometimes second to last, or a blank record, it becomes unselected and refreshes with the correct data. I am running on Win 2K.

    Not sure if I understand what you mean:
    I have yet to figure out how to fix this problem. I
    have a JTable that is refreshed often with new data
    from a database (Next and Previous). next/previous are buttons?
    If I select a
    JComboBox in the JTable, when I select Next or
    Previous the box remains selected the combo is still showing inside the table? And by select you mean pressing one of the button?
    If that's the situation then the table is still editing - by default it has a combo only as a cellEditor, not as a cellRenderer. So as long as the combo is showing the table did not stop editing - and while editing that particular value shown in the editor is never updated. And though the underlying tableModel is changed by some other event (like the db update) it is changed back to the value as shown in the editor when the editing is stopped some time later... confusing, isn't it?
    The way out is version dependent: safest because working in all jdk versions (except on 1.4.0 on the very first edit that ever happens on a table after startup) is to make sure that a possibly editing state of the table is stopped in your all your action handlers:
    actionPerformed(..) {
    if (table.isEditing()) {
    table.getCellEditor().stopCellEditing();
    // do your action
    That's undesirable for a couple of reasons (like f.i. the independent handlers need a reference back to table), so since 1.4.1 you can force the table to stop editing if the focus is transferred to the outside of the table. (it does not by default you have to set the client property "terminateEditOnFocusLost" to Boolean.TRUE)
    Greetings
    Jeanette

  • JTable with JComboBox/JSpinner problem

    The following code has a JTable with 2 columns.The lst column has JComboBoxes, the 2nd column has JSpinners.I want to set the spinner range of values based on the selection of JComboBox. The JComboBox selections are "small" and "large". For "small" the spinner should range from 0..49, for "large" from 50..99. When a selection is made, MyTable.itemStateChanged() is called, which in turn calls SpinnerEditor.setValueRange(). This sets an array with the desired values and then sets the model with this array. However, it sets the range not only for the row in which the combo box was clicked, but all rows.
    So in MyTable.setCellComponents(), there is this:
    spinnerEditor = new SpinnerEditor(this, defaultTableModel);
    modelColumn.setCellEditor(spinnerEditor);
    If the table has n rows, are n SpinnerEditors created, or just 1?
    If 1, do n need to be created and if so, how?
    public class MyTable extends JTable implements ItemListener {
         private DefaultTableModel defaultTableModel;
         private Vector<Object> columnNameVector;
         private JComboBox jComboBox;
         private SpinnerEditor spinnerEditor;
         private final int COMBO_BOX_COLUMN = 0;
         final static int SPINNER_COLUMN = 1;
         public static String SMALL = "Small";
         public String LARGE = "Large";
         private final String[] SMALL_LARGE = {
                   SMALL,
                   LARGE };
         public MyTable(String name, Object[][] variableNameArray, Object[] columnNameArray) {
              columnNameVector = new Vector<Object>();
              // need column names in order to make copy of table model
              for (Object object : columnNameArray) {
                   columnNameVector.add(object);
              defaultTableModel = new DefaultTableModel(variableNameArray, columnNameArray);
              this.setModel(defaultTableModel)     ;
              setCellComponents();
              setListeners();
         private void setCellComponents() {
              // combo box column -----------------------------------------------
              TableColumn modelColumn = this.getColumnModel().getColumn(COMBO_BOX_COLUMN);
              jComboBox = new JComboBox(SMALL_LARGE);
              // set default values
              for (int row = 0; row < defaultTableModel.getRowCount(); row++) {
                   defaultTableModel.setValueAt(SMALL_LARGE[0], row, COMBO_BOX_COLUMN);
              modelColumn.setCellEditor(new DefaultCellEditor(jComboBox));
              DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for small/large"); // tooltip
              modelColumn.setCellRenderer(renderer);
              // index spinner column ------------------------------------------------------------
              modelColumn = this.getColumnModel().getColumn(SPINNER_COLUMN);
              spinnerEditor = new SpinnerEditor(this, defaultTableModel);
              modelColumn.setCellEditor(spinnerEditor);
              renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for index value"); // tooltip
              modelColumn.setCellRenderer(renderer);
         private void setListeners() {
              jComboBox.addItemListener(this);
         @Override
         public void itemStateChanged(ItemEvent event) {
              // set spinner values depending on small or large
              String smallOrLarge = (String)event.getItem();
              if (this.getEditingRow() != -1 && this.getEditingColumn() != -1) {
                   spinnerEditor.setValueRange(smallOrLarge);
         public static void main(String[] args) {
              try{
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e){
                   e.printStackTrace();
              String[] columnNameArray = {"JComboBox", "JSpinner"};
              Object[][]  dataArray = {
                        {"", "0"},
                        {"", "0"},
                        {"", "0"},
              final MyTable myTable = new MyTable("called from main", dataArray, columnNameArray);
              final JFrame frame = new JFrame();
              frame.getContentPane().add(new JScrollPane(myTable));
              frame.setTitle("My Table");
              frame.setPreferredSize(new Dimension(200, 125));
              frame.addWindowListener(new WindowAdapter(){
                   @Override
                   public void windowClosing(WindowEvent e) {
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setLocation(800, 400);
              frame.pack();
              frame.setVisible(true);
    public class SpinnerEditor extends AbstractCellEditor implements TableCellEditor {
         private JComponent parent;
         private DefaultTableModel defaultTableModel;
         private final JSpinner spinner = new JSpinner();
         private String[] spinValues;
         private int row;
         private int column;
         public SpinnerEditor(JTable parent, DefaultTableModel defaultTableModel ) {
              super();
              this.parent = parent;
              this.defaultTableModel = defaultTableModel;
              setValueRange(MyTable.SMALL);
              // update every time spinner is incremented or decremented
              spinner.addChangeListener(new ChangeListener(){
                   public void stateChanged(ChangeEvent e) {
                        String value = (String) spinner.getValue();
                        System.out.println ("SpinnerEditor.stateChanged(): " + value);
                        setValue(value);
         private void setValue(String value) {
              // save to equation string
              System.out.println ("SpinnerEditor.setValue(): " + value + " at (" + row + ", " + MyTable.SPINNER_COLUMN + ")");
              ((JTable) parent).setValueAt(spinner.getValue(), this.row, this.column);
         @Override
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)      {
              System.out.println ("SpinnerEditor.getTableCellEditorComponent(): row: " + row + "\tcolumn: " + column);
              System.out.println ("SpinnerEditor.getTableCellEditorComponent(): value: " + value);
              this.row = row;
              this.column = column;
              return spinner;
         @Override
         public boolean isCellEditable(EventObject evt) {
              return true;
         // Returns the spinners current value.
         @Override
         public Object getCellEditorValue() {
              return spinner.getValue();
         @Override
         public boolean stopCellEditing() {
              System.out.println("SpinnerEditor.stopCellEditing(): spinner: " + spinner.getValue() + " at (" + this.row + ", " + this.column + ")");
              ((JTable) parent).setValueAt(spinner.getValue(), this.row, this.column);
              return true;
         public void setValueRange(String smallOrLarge) {
              System.out.println ("SpinnerEditor.setValueRange for " + smallOrLarge);
              final int ARRAY_SIZE = 50;
              if (MyTable.SMALL.equals(smallOrLarge)) {
                   final int MIN_SPIN_VALUE = 0;               
                   final int MAX_SPIN_VALUE = 49;
                   //System.out.println ("SpinnerEditor.setValueRange(): [" + MIN_SPIN_VALUE + ".." +  MAX_SPIN_VALUE + "]");
                   spinValues = new String[ARRAY_SIZE];
                   for (int i = MIN_SPIN_VALUE; i <= MAX_SPIN_VALUE; i++) {
                        spinValues[i] = new String(Integer.toString(i));
              else { // large
                   final int MIN_SPIN_VALUE = 50;               
                   final int MAX_SPIN_VALUE = 99;
                   //System.out.println ("SpinnerEditor.setValueRange(): [" + MIN_SPIN_VALUE + ".." +  MAX_SPIN_VALUE + "]");
                   spinValues = new String[ARRAY_SIZE];
                   for (int i = 0; i <ARRAY_SIZE; i++) {
                        spinValues[i] = new String(Integer.toString(MIN_SPIN_VALUE + i));
                   //for (int i = 0; i <ARRAY_SIZE; i++) {
                   //     System.out.println ("spinValues[" + i + "] = " + spinValues);
              System.out.println ("SpinnerEditor.setValueRange(): [" + spinValues[0] + ".." + spinValues[ARRAY_SIZE-1] + "]");
              // set model
              spinner.setModel(new SpinnerListModel(java.util.Arrays.asList(spinValues)));

    However, it sets the range not only for the row in which the combo box was clicked, but all rows. Yes, because a single editor is used by the column.
    One solution is to create two editors, then you override the getCellEditor(...) method to return the appropriated editor. Something like:
    If (column == ?)
        if (smallOrLarge)
          return the small or large spinner editor
        else
           return the large spinner editor
    else
        return super.getCellEditor(...);

  • Photoshop CS6 - Quick Selection tool freezes Photoshop/ becomes unresponsive for minutes

    After only two selections the tool becomes unresponsive for minutes.
    I'm on a 2.6 Ghz retina MacBook Pro, 16 Gb RAM, and this in connection with an SSD should make this tool very good to use. Operating system: OS X 10.8 "Mountain Lion", latest update.
    Unfortunately, it seems to develop some kind of overload, during which you cannot use Photoshop at all. No commands like "undo selection", "quit", "close file" are accepted.
    There is no beachball, no other signs that Photoshop is working on something.
    Hint: it seems to happen when you option select (subtract from an existing selection).
    Hint: the freeze can be shortened by a tool switch (has to be through clicking on a tool, keyboard commands are frozen as well)
    Hint: the "subtract selection" move that caused the freeze appears after Photoshop comes back to life after a couple of minutes. The subtraction to the selection seems to be random, makes no sense, and is not the regular function of the tool.
    First step after this freeze would be to undo the last selection, and continue working.
    If you do several "add to selection" moves, they add up in a kind of waiting line. If you do the subtract from selection move, this doesn't work, and the freeze happens.
    So far, I have not noticed the freeze when adding to a selection. Adding to a selection was always quick and instant. The bug must sit in the "subtract from selection" code.
    On most freezes, the ants continue walking, I just had one (again with subtracting selection) where even the ants stopped walking.
    I don't think it has anything to do with Photoshop working. I have used the quick selection tool regularly under CS5 on my old machine (which was a museum piece), and while I had to wait sometimes, it was never ground to a freeze/halt like the quick selection tool under CS6.

    Did this work before, or has it always been this way?  Not a bug or everyone with your system would be complaining.  Have not seen that.
    If it has always worked that way a reset of preferences will probably not do anything.
    A reset of preferences will reset to factory defaults, so you will have to reset to saved workspace.
    Do you have at least 10% free disk space? 

  • JComboBox addActionListener?

    Hi, I'm trying to write a program so that when the user makes a selection from the combobox, the selection will be inputted into a string.
    However, whenever I try to run the program it gives me this error:
    "Questions.java": addItemListener(java.awt.event.ItemListener) in javax.swing.JComboBox cannot be applied to (Questions) at line 120, column 15
    This is the part of my code which I think is relevent:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.io.*;
    public class Questions extends JFrame {
      private Container container;
      private GridBagLayout gbLayout;
      private GridBagConstraints gbConstraints;
      private ButtonGroup radioGroup;
      JLabel correctL, incorrectL, correctNumL, incorrectNumL,
          youSelectL, correctSelectL;
      JButton nextB, exitB, guessB;
      JCheckBox aCB, bCB, cCB, dCB;
      JTextArea questionTA;
      JComboBox selection = new JComboBox();
      public static int qNum[] = new int[20];
      public static String question[] = new String[20];
      public static String choiceA[] = new String[20];
      public static String choiceB[] = new String[20];
      public static String choiceC[] = new String[20];
      public static String choiceD[] = new String[20];
      public static String answer[] = new String[20];
      public static int recordNum = (int) (Math.random() * 20);
      public static int total = 0;
      public static int right = 0;
      public static int wrong = 0;
      public static String whichQselected;
      public static boolean qAnswered = false;
      nextButtonHandler nextHandler;
      guessButtonHandler guessHandler;
      exitButtonHandler exitHandler;
      public Questions() {
        super("Questions");
        setContentPane(new ContentPanel("bg.gif"));
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        container = getContentPane();
        gbLayout = new GridBagLayout();
        container.setLayout(gbLayout);
        gbConstraints = new GridBagConstraints();
        questionTA = new JTextArea(question[recordNum], 3, 23);
        questionTA.setForeground(Color.blue);
        questionTA.setFont(new Font("Impact", Font.PLAIN, 15));
        questionTA.setWrapStyleWord(true);
        questionTA.setLineWrap(true);
        questionTA.setEditable(false);
        correctL = new JLabel("Correct Answers: ");
        correctL.setForeground(Color.magenta);
        correctL.setFont(new Font("Ariel", Font.PLAIN, 10));
        correctNumL = new JLabel("0/0");
        correctNumL.setForeground(Color.magenta);
        correctNumL.setFont(new Font("Ariel", Font.PLAIN, 10));
        incorrectL = new JLabel("Incorrect Answers: ");
        incorrectL.setForeground(Color.red);
        incorrectL.setFont(new Font("Ariel", Font.PLAIN, 10));
        incorrectNumL = new JLabel("0/0");
        incorrectNumL.setForeground(Color.red);
        incorrectNumL.setFont(new Font("Ariel", Font.PLAIN, 10));
        youSelectL = new JLabel("You've selected:");
        youSelectL.setForeground(Color.orange);
        youSelectL.setFont(new Font("Ariel", Font.BOLD, 13));
        correctSelectL = new JLabel("The Correct answer is: ");
        correctSelectL.setForeground(Color.ORANGE);
        correctSelectL.setFont(new Font("Ariel", Font.BOLD, 13));
        nextB = new JButton("Next Question");
        nextHandler = new nextButtonHandler();
        nextB.addActionListener(nextHandler);
        nextB.setBackground(Color.WHITE);
        guessB = new JButton("Guess Picture");
        guessHandler = new guessButtonHandler();
        guessB.addActionListener(guessHandler);
        guessB.setBackground(Color.WHITE);
        exitB = new JButton("Exit");
        exitHandler = new exitButtonHandler();
        exitB.addActionListener(exitHandler);
        exitB.setBackground(Color.WHITE);
        aCB = new JCheckBox(choiceA[recordNum]);
        aCB.setBackground(Color.white);
        bCB = new JCheckBox(choiceB[recordNum]);
        bCB.setBackground(Color.white);
        cCB = new JCheckBox(choiceC[recordNum]);
        cCB.setBackground(Color.white);
        dCB = new JCheckBox(choiceD[recordNum]);
        dCB.setBackground(Color.white);
        //register events
        CheckBoxHandler handler = new CheckBoxHandler();
        aCB.addItemListener(handler);
        bCB.addItemListener(handler);
        cCB.addItemListener(handler);
        dCB.addItemListener(handler);
        //PROBLEM HERE!!!
        selection.addItemListener(this);
        selection.addItem("Geography Questions");
        selection.addItem("Math Questions");
        selection.addItem("Mixed Questions");
        selection.addItem("Music Questions");
        selection.addItem("Sports Questions");
        selection.addItem("TV Questions");
        addComponent(selection, 0, 0, 3, 1);
        addComponent(questionTA, 1, 0, 3, 1);
        addComponent(aCB, 2, 0, 1, 1);
        addComponent(bCB, 3, 0, 1, 1);
        addComponent(cCB, 4, 0, 1, 1);
        addComponent(dCB, 5, 0, 1, 1);
        addComponent(correctL, 2, 1, 1, 1);
        addComponent(correctNumL, 2, 2, 1, 1);
        addComponent(incorrectL, 2, 1, 1, 1);
        addComponent(incorrectNumL, 2, 2, 1, 1);
        addComponent(nextB, 6, 0, 1, 1);
        addComponent(guessB, 6, 1, 1, 1);
        addComponent(exitB, 6, 2, 1, 1);
        addComponent(youSelectL, 7, 0, 2, 1);
        addComponent(correctSelectL, 8, 0, 2, 1);
        gbConstraints.fill = GridBagConstraints.BOTH;
        setSize(420, 350);
        show();
    //ACTION PERFORMED FOR JCOMBOBOX!!
      public void actionPerformed(ActionEvent e) {
        String whichQ[] = {"Geography", "Math",
                          "Mixed", "Music", "Sports", "TV"};
        int Selected = ((JComboBox) (e.getSource())).getSelectedIndex();
        whichQselected = whichQ[Selected];
      }Thanks in advance!

    Also, you have added an item listener and implemented the method from the action listener. Above all, you did not declare your class as implementing the ActionListener interface.

  • UNDO Tablespace Issue - URGENT

    I had issues with UNDO. Here is what happened -
    SQL> alter tablespace UNDO
    2 add datafile '/oracle/TESTDB/data04/TESTDB_undo_04.db' size 100M autoextend on maxsize 10000M;
    SQL> select file_name,bytes/1024/1024 MB, maxbytes/1024/1024 MMB from dba_data_files where tablespace_name='UNDO';
    FILE_NAME MB MMB
    /oracle/TESTDB/data02/TESTDB_undo_01.dbf 6158 10240
    /oracle/TESTDB/data01/TESTDB_undo_02.dbf 7703 0
    /oracle/TESTDB/data03/TESTDB_undo_03.dbf 7636 0
    /oracle/TESTDB/data04/TESTDB_undo_04.db 100 10000
    But after some time this same query gave me this error -
    SQL> select file_name,bytes/1024/1024 MB, maxbytes/1024/1024 MMB from dba_data_files where tablespace_name='UNDO';
    FILE_NAME MB MMB
    /oracle/TESTDB/data02/TESTDB_undo_01.dbf 6158 10240
    /oracle/TESTDB/data01/TESTDB_undo_02.dbf 7703 0
    /oracle/TESTDB/data03/TESTDB_undo_03.dbf 7636 0
    /oracle/TESTDB/data04/TESTDB_undo_04.db
    Users then started complaining about it.
    Queries like this also started giving us these problems -
    SQL> select file_id,file_name,bytes/1024/1024 MB, maxbytes/1024/1024 MMB,status from dba_data_files where tablespace_name='UNDO';
    select file_id,file_name,bytes/1024/1024 MB, maxbytes/1024/1024 MMB,status from dba_data_files where tablespace_name='UNDO'
    ERROR at line 1:
    ORA-00376: file 67 cannot be read at this time
    ORA-01110: data file 67: '/oracle/TESTDB/data04/TESTDB_undo_04.db'
    Then I though of bouncing the database but then it also giving some problem -
    SQL> shutdown immediate;
    ORA-00376: file 67 cannot be read at this time
    ORA-01110: data file 67: '/oracle/TESTDB/data04/TESTDB_undo_04.db'
    SQL> exit
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    TESTDB - /oracle/TESTDB/data03> sqlplus / as sysdba
    SQL*Plus: Release 11.1.0.7.0 - Production on Fri Jul 30 09:27:24 2010
    Copyright (c) 1982, 2008, Oracle. All rights reserved.
    Connected.
    SQL> shutdown abort;
    ORACLE instance shut down.
    SQL> startup;
    ORACLE instance started.
    Total System Global Area 4175568896 bytes
    Fixed Size 2160352 bytes
    Variable Size 3137341728 bytes
    Database Buffers 1023410176 bytes
    Redo Buffers 12656640 bytes
    Database mounted.
    ORA-00376: file 67 cannot be read at this time
    ORA-01110: data file 67: '/oracle/TESTDB/data04/TESTDB_undo_04.db'
    Thought of recovering the this tablespace but still getting this error -
    RMAN> recover tablespace "UNDO";
    Starting recover at 30-JUL-10
    starting full resync of recovery catalog
    full resync complete
    allocated channel: ORA_SBT_TAPE_1
    channel ORA_SBT_TAPE_1: SID=278 device type=SBT_TAPE
    channel ORA_SBT_TAPE_1: Data Protection for Oracle: version 5.5.1.0
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=277 device type=DISK
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of recover command at 07/30/2010 09:34:17
    ORA-00376: file 67 cannot be read at this time
    ORA-01110: data file 67: '/oracle/TESTDB/data04/TESTDB_undo_04.db'
    Will greatly appreciate if someone can give some advice here.

    TESTDB - /oracle/TESTDB/data04> ls -ltr
    total 25751072
    drwxr-xr-x 2 oracle dba 256 Apr 9 10:09 lost+found
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:08 TESTDB_undo_04.db
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_paipas_idx_256k_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_cmwdgt_tab_1m_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_cmwdgt_idx_256k_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_cmpcc_idx_256k_a_01
    -rw-r----- 1 oracle dba 232792064 Jul 30 09:50 TESTDB_cmcap_tab_1m_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_cmcap_idx_256k_a_01
    -rw-r----- 1 oracle dba 504373248 Jul 30 09:50 TESTDB_cctlrpt_tab_1m_a_01
    -rw-r----- 1 oracle dba 1356865536 Jul 30 09:50 TESTDB_ccstgrpt_tab_1m_a_01
    -rw-r----- 1 oracle dba 4481622016 Jul 30 09:50 TESTDB_ccoprpt_tab_1m_a_01
    -rw-r----- 1 oracle dba 653271040 Jul 30 09:50 TESTDB_ccindrpt_idx_256K_a_01
    -rw-r----- 1 oracle dba 2752520192 Jul 30 09:50 TESTDB_cccnv_tab_1m_a_02.dbf
    -rw-r----- 1 oracle dba 168828928 Jul 30 09:50 TESTDB_ccadmrpt_tab_1m_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_cmwos_idx_256k_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_cmgcd_idx_256k_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:50 TESTDB_cmfos_idx_256k_a_01
    -rw-r----- 1 oracle dba 247472128 Jul 30 09:52 TESTDB_cmpcc_tab_1m_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:53 TESTDB_cmpe_tab_1m_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:53 TESTDB_cmpe_idx_256k_a_01
    -rw-r----- 1 oracle dba 104865792 Jul 30 09:54 TESTDB_cmgcd_tab_1m_a_01
    -rw-r----- 1 oracle dba 247472128 Jul 30 09:57 TESTDB_cmwos_tab_1m_a_01
    -rw-r----- 1 oracle dba 364912640 Jul 30 09:58 TESTDB_cmfos_tab_1m_a_01
    -rw-r----- 1 oracle dba 916004864 Jul 30 09:58 TESTDB_sysaux_02.dbf

  • JComboBox + Hasmap

    I know this must seem like a completely newbie question and I thought I was doing it correct but something somewhere is going wrong.
    I have a Hashmap that contains arrays of BigDecimal with keys such as 1.00,1.002, 12.004 etc. as strings.
    If surfacePipeNumber is the JComboBox shouldnt the next line return the contents of the selected item as a string?
    (surfacePipeNumber.getSelectedItem()).toString()
    I have added a actionListener to a JComboBox where it makes a clone of the correct array and sets the correct JTextFields with each part of the array.
    Heres an example:
         public void UpdateSurfaceFields(){
              System.out.println(surfaceWaterData.get(surfacePipeNumber.getSelectedItem()).toString());
              BigDecimal [] tempSurfaceArray = surfaceWaterData.get(surfacePipeNumber.getSelectedItem().toString()).clone();
              surfacePipeLength.setText(tempSurfaceArray[0].toString());
              surfaceDSInvertLevel.setText(tempSurfaceArray[1].toString());
              surfacePipeDiameter.setText(tempSurfaceArray[2].toString());
              surfacePipeSlope.setText(tempSurfaceArray[3].toString());
              surfaceUSEasting.setText(tempSurfaceArray[4].toString());
              surfaceUSNorthing.setText(tempSurfaceArray[5].toString());
              surfaceDSEasting.setText(tempSurfaceArray[6].toString());
              surfaceDSNorthing.setText(tempSurfaceArray[7].toString());
         }The test System.out.println line I added returns:
    [Ljava.math.BigDecimal;@1c282a1
    So is this a string or a BigDecimal?
    I dont know if this matters but I also have a refresh button which addItem to the JComboBox from a scanned in text file. I press the refresh button before I select the JcomboBox which succesfully updates the JComboBox and seems to run my method on its own for some reason but does it correctly, after that it returns a NullPointerException.
    I know if the Hashmap couldnt find the key it would return null but before when the JComboBox was a JTextField it worked fine.
    Thanks,
    Ken

    Yes sorry I didnt have much time to do it in the week but I have now done it,
    I've just tried to cut it down so its the same but with less data/fields to handle.
    Sorry if theres still alot.
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JComboBox;
    import javax.swing.border.TitledBorder;
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import java.awt.GridLayout;
    import java.awt.BorderLayout;
    import java.util.HashMap;
    import java.math.BigDecimal;
    public class DrainageWorkbook extends JFrame{
         private JTextField surfacePipeLength;
         private JTextField surfaceDSInvertLevel;
         private JTextField surfacePipeDiameter;
         private JTextField foulPipeLength;
         private JTextField foulDSInvertLevel;
         private JTextField foulPipeDiameter;
         private JTextField surfaceFilePath, foulFilePath;
         private JButton surfaceBrowse, foulBrowse, refresh;
         private JComboBox surfacePipeNumber;
         private JComboBox foulPipeNumber;
         private static HashMap<String, Pipe> surfaceWaterData;
         private static HashMap<String, Pipe> foulWaterData;
         public static boolean dataImported = false;
         DrainageWorkbook(String title) {
              super(title);
              surfaceWaterData  = new HashMap<String, Pipe>();
              foulWaterData  = new HashMap<String, Pipe>();
              surfacePipeNumber = new JComboBox();
              foulPipeNumber = new JComboBox();
              //Surface Water Fields created and setup
              surfacePipeNumber.addActionListener(new pipeNameListener(surfaceWaterData, foulWaterData,surfacePipeNumber, surfacePipeLength, surfaceDSInvertLevel, surfacePipeDiameter, foulPipeNumber, foulPipeLength, foulDSInvertLevel, foulPipeDiameter));
              surfacePipeLength = new JTextField(10);
              surfacePipeLength.setEditable(false);
              surfaceDSInvertLevel = new JTextField(10);
              surfaceDSInvertLevel.setEditable(false);
              surfacePipeDiameter = new JTextField(10);
              surfacePipeDiameter.setEditable(false);
              //Foul Water Fields created and setup
              foulPipeNumber.addActionListener(new pipeNameListener(surfaceWaterData, foulWaterData, surfacePipeNumber, surfacePipeLength, surfaceDSInvertLevel, surfacePipeDiameter, foulPipeNumber, foulPipeLength, foulDSInvertLevel, foulPipeDiameter));
              foulPipeLength = new JTextField(10);
              foulPipeLength.setEditable(false);
              foulDSInvertLevel = new JTextField(10);
              foulDSInvertLevel.setEditable(false);
              foulPipeDiameter = new JTextField(10);
              foulPipeDiameter.setEditable(false);
              //Create Surface water panel that conatains all surface water fields
              JPanel SurfaceWaterPanel = new JPanel();
              SurfaceWaterPanel.setLayout(new GridLayout(0,2));
              SurfaceWaterPanel.add(new JLabel("Pipe Number: "));
              SurfaceWaterPanel.add(surfacePipeNumber);
              SurfaceWaterPanel.add(new JLabel("Pipe Length: "));
              SurfaceWaterPanel.add(surfacePipeLength);
              SurfaceWaterPanel.add(new JLabel("DS Invert Level: "));
              SurfaceWaterPanel.add(surfaceDSInvertLevel);
              SurfaceWaterPanel.add(new JLabel("Pipe Diameter: "));
              SurfaceWaterPanel.add(surfacePipeDiameter);
              TitledBorder surfaceWaterTitle;
              surfaceWaterTitle = BorderFactory.createTitledBorder("Surface Water Drainage");
              SurfaceWaterPanel.setBorder(surfaceWaterTitle);
              //Create Foul water panel that conatains all foul water fields
              JPanel FoulWaterPanel = new JPanel();
              FoulWaterPanel.setLayout(new GridLayout(0,2));
              FoulWaterPanel.add(new JLabel("Pipe Number: "));
              FoulWaterPanel.add(foulPipeNumber);
              FoulWaterPanel.add(new JLabel("Pipe Length: "));
              FoulWaterPanel.add(foulPipeLength);
              FoulWaterPanel.add(new JLabel("DS Invert Level: "));
              FoulWaterPanel.add(foulDSInvertLevel);
              FoulWaterPanel.add(new JLabel("Pipe Diameter: "));
              FoulWaterPanel.add(foulPipeDiameter);
              TitledBorder foulWaterTitle;
              foulWaterTitle = BorderFactory.createTitledBorder("Foul Water Drainage");
              FoulWaterPanel.setBorder(foulWaterTitle);
              //Buttons/Fields for locating drainage text files
              surfaceFilePath = new JTextField();
              surfaceBrowse = new JButton("Browse...");
              surfaceBrowse.addActionListener(new fileFinderListener(surfaceFilePath));
              foulFilePath = new JTextField();
              foulBrowse = new JButton("Browse...");
              foulBrowse.addActionListener(new fileFinderListener(foulFilePath));
              //Distance panel
              refresh = new JButton("Refresh");
              refresh.addActionListener(new refreshListener(surfaceFilePath, foulFilePath, surfaceWaterData, foulWaterData, surfacePipeNumber, surfacePipeLength, foulPipeNumber));
              JPanel distancePanel = new JPanel();
              distancePanel.setLayout(new BoxLayout(distancePanel,BoxLayout.LINE_AXIS));
              distancePanel.add(refresh);
              //Drainage text file panels
              JPanel surfaceFilePanel = new JPanel();
              surfaceFilePanel.setLayout(new BoxLayout(surfaceFilePanel,BoxLayout.LINE_AXIS));
              surfaceFilePanel.add(new JLabel("Surface water file Path:  "));
              surfaceFilePanel.add(surfaceFilePath);
              surfaceFilePanel.add(surfaceBrowse);
              JPanel foulFilePanel = new JPanel();
              foulFilePanel.setLayout(new BoxLayout(foulFilePanel,BoxLayout.LINE_AXIS));
              foulFilePanel.add(new JLabel("Foul water file Path:         "));
              foulFilePanel.add(foulFilePath);
              foulFilePanel.add(foulBrowse);
              //Combine all panels to go at bottom of program
              JPanel bottomPanel = new JPanel();
              bottomPanel.setLayout(new BoxLayout(bottomPanel,BoxLayout.PAGE_AXIS));
              bottomPanel.add(distancePanel);
              bottomPanel.add(surfaceFilePanel);
              bottomPanel.add(foulFilePanel);
              //Combined panel for surface water and foul water fields
              JPanel CombinedPanel = new JPanel();
              CombinedPanel.setLayout(new GridLayout(0,2));
              CombinedPanel.add(SurfaceWaterPanel);
              CombinedPanel.add(FoulWaterPanel);
              this.setLayout(new BorderLayout());
              this.add(CombinedPanel, BorderLayout.CENTER);
              this.add(bottomPanel, BorderLayout.SOUTH);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public static void main(String[] args) {
              DrainageWorkbook DWB = new DrainageWorkbook("DrainageWorkbook v0.1 Alpha");
              DWB.setSize(600,400);
              DWB.setVisible(true);
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.HashMap;
    import java.util.Scanner;
    import javax.swing.JComboBox;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class refreshListener implements ActionListener{
         private JTextField surfaceFilePath;
         private JTextField foulFilePath;
         private HashMap<String, Pipe> surfaceWaterData;
         private HashMap<String, Pipe> foulWaterData;
         private File surfaceFile, foulFile;
         private Scanner readSurfaceFile, readFoulFile, processSurfaceLine, processFoulLine;
         private JComboBox surfacePipeNumber, foulPipeNumber;
         public static boolean surfaceDataImported = false, foulDataImported = false;
         refreshListener(JTextField sfp, JTextField ffp, HashMap<String, Pipe> swd, HashMap<String, Pipe> fwd,
                             JComboBox spn, JTextField spl, JComboBox fpn){
              surfaceFilePath = sfp;
              foulFilePath = ffp;
              surfaceWaterData = swd;
              foulWaterData = fwd;
              surfacePipeNumber = spn;          
              foulPipeNumber = fpn;
         public void actionPerformed(ActionEvent e){
              UpdateSurfaceData();
              UpdateFoulData();
         public void UpdateSurfaceData(){
              try{
                   surfaceWaterData.clear();
                   surfacePipeNumber.removeAllItems();
                   surfaceFile = new File(surfaceFilePath.getText());
                   readSurfaceFile = new Scanner(surfaceFile);
                   while(readSurfaceFile.hasNextLine()){
                        String pipeName;
                        processSurfaceLine = new Scanner(readSurfaceFile.nextLine());
                        processSurfaceLine.useDelimiter(",");
                        pipeName = processSurfaceLine.next();
                        Pipe surfacePipe = new Pipe(pipeName, 'S');
                        surfacePipeNumber.addItem(surfacePipe.getName());
                        surfacePipe.setLength(processSurfaceLine.next());
                        surfacePipe.setDSInvertLevel(processSurfaceLine.next());
                        surfacePipe.setDiameter(processSurfaceLine.next());
                        surfacePipe.setSlope(processSurfaceLine.next());
                        surfaceWaterData.put(surfacePipe.getName(), surfacePipe);
                        surfaceDataImported = true;
                   JOptionPane.showMessageDialog(null, "Surface Water Data was successfully imported!\r\nType in the surface water pipe number to update the fields", "Surface Water Update Complete", JOptionPane.INFORMATION_MESSAGE);
              }catch (FileNotFoundException ex){
                   JOptionPane.showMessageDialog(null, "One of the drainage files could not be found", "File not found", JOptionPane.ERROR_MESSAGE);
              }finally{
                   if(readSurfaceFile != null)
                   readSurfaceFile.close();
                   if(processSurfaceLine != null)
                   processSurfaceLine.close();
         public void UpdateFoulData(){
              try{
                   foulWaterData.clear();
                   foulPipeNumber.removeAllItems();
                   foulFile = new File(foulFilePath.getText());
                   readFoulFile = new Scanner(foulFile);
                   while(readFoulFile.hasNextLine()){
                        String pipeName;
                        processFoulLine = new Scanner(readFoulFile.nextLine());
                        processFoulLine.useDelimiter(",");
                        pipeName = processFoulLine.next();
                        Pipe foulPipe = new Pipe(pipeName, 'F');
                        foulPipeNumber.addItem(foulPipe.getName());
                        foulPipe.setLength(processFoulLine.next());
                        foulPipe.setDSInvertLevel(processFoulLine.next());
                        foulPipe.setDiameter(processFoulLine.next());
                        foulPipe.setSlope(processFoulLine.next());
                        foulWaterData.put(foulPipe.getName(), foulPipe);
                        foulDataImported = true;
                   JOptionPane.showMessageDialog(null, "Foul Water Data was successfully imported!\r\nType in the foul water pipe numbers to update the fields", "Foul Water Update Complete", JOptionPane.INFORMATION_MESSAGE);
              }catch (FileNotFoundException ex){
                   JOptionPane.showMessageDialog(null, "One of the drainage files could not be found", "File not found", JOptionPane.ERROR_MESSAGE);
              }finally{
                   if(readSurfaceFile != null)
                   readSurfaceFile.close();
                   if(processSurfaceLine != null)
                   processSurfaceLine.close();
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.math.BigDecimal;
    import java.util.HashMap;
    import javax.swing.JComboBox;
    import javax.swing.JTextField;
    public class pipeNameListener implements ActionListener{
         private HashMap<String, Pipe> surfaceWaterData;
         private HashMap<String, Pipe> foulWaterData;
         private JTextField surfacePipeLength, surfaceDSInvertLevel, surfacePipeDiameter;
         private JTextField foulPipeLength, foulDSInvertLevel, foulPipeDiameter;
         private JComboBox surfacePipeNumber, foulPipeNumber;
         private Pipe surfacePipeSelected, foulPipeSelected;
         pipeNameListener(HashMap<String, Pipe> swd, HashMap<String, Pipe> fwd,
                   JComboBox spn, JTextField spl, JTextField sdsil, JTextField spd,
                   JComboBox fpn, JTextField fpl, JTextField fsail, JTextField fpd){
              surfaceWaterData = swd;
              foulWaterData = fwd;
              surfacePipeNumber = spn;
              surfacePipeLength = spl;
              surfaceDSInvertLevel = sdsil;
              surfacePipeDiameter = spd;
              foulPipeNumber = fpn;
              foulPipeLength = fpl;
              foulDSInvertLevel = fsail;
              foulPipeDiameter = fpd;
         public void actionPerformed(ActionEvent e) {
              if(refreshListener.surfaceDataImported)
                   UpdateSurfaceFields();
              if(refreshListener.foulDataImported)
                   UpdateFoulFields();
         public void UpdateSurfaceFields(){
              surfacePipeSelected = surfaceWaterData.get(surfacePipeNumber.getSelectedItem().toString());
              surfacePipeLength.setText(surfacePipeSelected.getLength().toString());
              surfaceDSInvertLevel.setText(surfacePipeSelected.getDSInvertLevel().toString());
              surfacePipeDiameter.setText(surfacePipeSelected.getDiameter().toString());
         public void UpdateFoulFields(){
              foulPipeSelected = foulWaterData.get((foulPipeNumber.getSelectedItem()));
              foulPipeLength.setText((foulPipeSelected.getLength()).toString());
              foulDSInvertLevel.setText(foulPipeSelected.getDSInvertLevel().toString());
              foulPipeDiameter.setText(foulPipeSelected.getDiameter().toString());
    import java.math.BigDecimal;
    import javax.swing.JOptionPane;
    public class Pipe{
    String Name;
    char type;
    BigDecimal Length;
    BigDecimal DSInvertLevel;
    BigDecimal Diameter;
    BigDecimal Slope;
         Pipe(String pipeName, char pipeType){
              Name = pipeName;
              type = pipeType;
         public String getName(){
              return Name;
         public void setLength(String l){
              try{
                   Length = new BigDecimal(l);
              }catch (NumberFormatException nf){
                   JOptionPane.showMessageDialog(null, "The length for pipe " + Name + " is in an incorrect number format.", "Number Format Error", JOptionPane.ERROR_MESSAGE);
         public BigDecimal getLength(){
              return Length;
         public void setDSInvertLevel(String dsil){
              try{
                   DSInvertLevel = new BigDecimal(dsil);
              }catch (NumberFormatException nf){
                   JOptionPane.showMessageDialog(null, "The Downstream invert level for pipe " + Name + " is in an incorrect number format.", "Number Format Error", JOptionPane.ERROR_MESSAGE);
         public BigDecimal getDSInvertLevel(){
              return DSInvertLevel;
         public void setDiameter(String d){
              try{
                   Diameter = new BigDecimal(d);
              }catch (NumberFormatException nf){
                   JOptionPane.showMessageDialog(null, "The diameter for pipe " + Name + " is in an incorrect number format.", "Number Format Error", JOptionPane.ERROR_MESSAGE);
         public BigDecimal getDiameter(){
              return Diameter;
         public void setSlope(String s){
              try{
                   Slope = new BigDecimal(s);
              }catch (NumberFormatException nf){
                   JOptionPane.showMessageDialog(null, "The slope for pipe " + Name + " is in an incorrect number format.", "Number Format Error", JOptionPane.ERROR_MESSAGE);
         public BigDecimal getSlope(){
              return Slope;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.JFrame;
    import java.io.File;
    public class fileFinderListener implements ActionListener{
         private JTextField filePath;
         fileFinderListener(JTextField fp){
              filePath = fp;
         public void actionPerformed(ActionEvent e) {
              JFileChooser fc = new JFileChooser();
              fc.addChoosableFileFilter(new FileSelectFilter());
              fc.setAcceptAllFileFilterUsed(false);
            int returnVal = fc.showOpenDialog(new JFrame());
            if (returnVal == JFileChooser.APPROVE_OPTION){
                File file = fc.getSelectedFile();
                filePath.setText(file.getAbsolutePath()) ;
            } else {
                 JOptionPane.showMessageDialog(null, "File selection cancelled by user. ", "File Selection", JOptionPane.INFORMATION_MESSAGE );
    import javax.swing.filechooser.FileFilter;
    import java.io.File;
    public class FileSelectFilter extends FileFilter {
        //Accept all directories and all txt and csv files.
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            String extension = getExtension(f);
            if (extension != null) {
                if (extension.equals("txt") ||
                    extension.equals("csv")){
                        return true;
                } else {
                    return false;
            return false;
        public static String getExtension(File f) {
            String ext = null;
            String s = f.getName();
            int i = s.lastIndexOf('.');
            if (i > 0 &&  i < s.length() - 1) {
                ext = s.substring(i+1).toLowerCase();
            return ext;
        //The description of this filter
        public String getDescription() {
            return "Text Files (.txt, .csv)";
    }

Maybe you are looking for