Wednesday, February 18, 2015

How to split a string with pipeline "|"

The pipeline is a special character. You need to add the escape in front of it.

The following code shall work.

String str = "54322|Good Stuff|beautiful|great";
String[] result = str.split("\\|");

for (String s : result) {
       System.out.println(s);
}

The output will be:

54322
Good Stuff
beautiful
great

---------------------------------------------------------------------------------------------------------------

                        
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 free here.

Thursday, February 12, 2015

JTable: Bottom of text is cut / cropped when using customized table cell renderer

The same type of text looks fine in columns using the default table cell renderer, but the bottom of the text is cut in columns using a customized table cell renderer. The bottom of text is cut because the customized table cell renderer adds a border which occupies some space. All you need to do to fix it is to set the border to null.

        public class MyFieldRenderer extends DefaultTableCellRenderer {

               public Component getTableCellRendererComponent(
                       JTable table, Object value,
                       boolean isSelected,
                       boolean hasFocus,
                       int row, int col) {

                       JComponent cpnt = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
                       cpnt.setBorder(null);

                       return cpnt;
               }
       }

If the text is cut all over the table, you may consider to use a smaller font or set the row height of the table to a larger value.

      Font font = table.getFont();
      table.setFont(font.getFamily(), font.getStyle(), <your size>);

      table.setRowHeight(int rowHeightInPixel);

----------------------------------------------------------------------------------------------------------------------

                        
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 free here.

JTable: Not allowing / disabling user to reorder columns or drag columns to new locations

To not allow reordering columns by dragging them around, add the following lines to your code.

JTable table = <your constructor of JTable>;

table.getTableHeader().setReorderingAllowed(false);

-----------------------------------------------------------------------------------------------------------------

                        
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 free here.

Tuesday, February 10, 2015

SQL: How to view information of the indexes of a table (INDEX_OWNER, COLUMN_NAME, UNIQUENESS)

The Following sql would return these information of the indexes of a table.

SELECT
      col.index_owner,
      ind.index_name,
      DECODE(ind.uniqueness, 'UNIQUE', 'YES', 'NO') UNIQUENESS,
      col.column_name,
      col.column_position,
      ind.tablespace_name
FROM dba_ind_columns col, dba_indexes ind
WHERE ind.index_name = col.index_name
      AND ind.table_name='<table_name>'
      AND ind.table_owner = col.table_owner
ORDER BY col.index_owner, ind.index_name, col.column_position;

-------------------------------------------------------------------------------------------------

                        
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 free here.

Thursday, February 5, 2015

NetBeans: Could not find or load main class

If a main class has been running fine and then suddenly having the "Could not find or load main class" error, it is most likely caused by NetBeans not being in its best state, especially when notifications of low memory are issued. Addressing these issues to let NetBeans work in its proper state will usually solve the problem.

To solve the NetBeans low memory problem, please read this post : NetBeans low memory/not enough memory to compile

---------------------------------------------------------------------------------------------------------------------        
                        
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 free here.

NetBeans: error parsing file

The java file in NetBeans IDE is marked by an error marker that is caused by error parsing the file. This is often caused by that NetBeans is not in its best state, especially when notifications of low memory are issued. Addressing these issues to let NetBeans work in its proper state will usually solve the problem.

To solve the NetBeans low memory problem, please read this post : NetBeans low memory/not enough memory to compile

---------------------------------------------------------------------------------------------------------------------
       
                        
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 free here.