Tuesday, February 28, 2017

[Solved] NetBeans: How to set the Libraries Folder to the default blank value?

When you right click the project, choose Properties, and then select Libraries under the Categories on the left, the Libraries Folder is located at the right side of the window.

If you have, by accident, set the Libraries Folder to something you did not mean to, such as by clicking the Browse button next to it,  it will give you compiling warnings and errors for not able to locate the jars in your libraries. You may follow the steps below to set it back to blank.
  1. Select the project in the Navigation pane.
  2. Click the Files tab at the top of the Navigation pane.
  3. Open the project.xml in the nbproject folder.
  4. Remove the <libraries> tag pairs and everything in between.
  5. If necessary, remove all the Compile-time Libraries and add them back from the correct folder.
  6. If you have problem during compiling such as "Netbeans Source resource does not exist",  temporarily rename the project to something else,  clean and build the project, then name back your project and do another clean and build.

References:


-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Friday, February 24, 2017

[Solved] java.lang.RuntimeException: Cannot use this method with a non-Mutable data model

The code below throws the java.lang.RuntimeException: Cannot use this method with a non-Mutable data model exception.

public class MyComboBoxModel<Student> implements ComboBoxModel<Student> {
      private ArrayList<Parent> parents;
      private DefaultComboBoxModel<Student> students;

      public MyComboBoxModel() {
            parents = new ArrayList<>();
            students = new DefaultComboBoxModel<>();
      }

      public MyComboBoxModel(Object[][] spPares) {
            parents = new ArrayList<>();
            students = new DefaultComboBoxModel<>();
            for (Object[] sp : spPares) {
                  students.addElement((Student)sp[0]);
                  parents.add((Parent)sp[1]);
           }
      }

      public Student getSelectedItem() {
            return (Student) students.getSelectedItem();
      }

      public Parent getSelectedParent() {
            int idx = students.getIndexOf(students.getSelectedItem());
            return parents.get(idx);
      }

      public void addElement(Object[] theV) {
            students.addElement((Student)theV[0]);
            parents.add((Parent)theV[1]);
      }

      public void insertElementAt(Object[] theV, int idx) {
            students.insertelementAt((Student) theV[0], idx);
            parents.add(idx, (Parent) theV[1]);
      }

      public void removeElement(Student s) {
            int idx = students.getIndexOf(s);
            parents.remove(idx);
            students.removeElement(s);
     }

     public void removeElementAt(int idx) {
           parent.remove(idx);
           students.removeElementAt(idx);
     }
}

public class Test extends JFrame{
     public Test() {
            JComboBox testBox = new JComboBox();
            testBox.setModel(new MyComboBoxModel());

            // this line of code throws the exception
            testBox.addElement(new Object[]{new Student("Tom"), new Parent("John")});

            getContentPane().add(testBox);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           setVisible(true);
     }

     public static void main (String[] args) {
           new Test();
     }
}

To fix this problem, change the first line of the MyComboBoxModel
from
       public class MyComboBoxModel<Student> implements ComboBoxModel<Student>
to
       public class MyComboBoxModel<Student> implements MutableComboBoxModel<Student>

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.