Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: please help to solve number display in E7

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help to solve number display in E7

    Hi, please help.
    i'm having problem in my code, that a number display in E7 example 10.000.000 it display as 1E7.

    here is my code:

    private void GridListing() {
    try {
    statement = DBConnections.getDBConnectionSys().createStatement ();
    if (jSearchBy1.getSelectedItem() == "Kode Jurnal")
    Criteria = " WHERE journal_no Like '" + jTxtSearch1.getText() + "%'";
    else if (jSearchBy1.getSelectedItem() == "Tanggal Jurnal")
    Criteria = " WHERE journal_date '" + jTxtSearch1.getText() + "%'";
    //Different DB Different Terms of Syntax
    if (GlobalSettings.dataBaseType == 1 || GlobalSettings.dataBaseType == 2) {
    Query = ("SELECT TOP 100 * FROM " + Table + Criteria); }
    if (GlobalSettings.dataBaseType == 3 || GlobalSettings.dataBaseType == 4) {
    Query = ("SELECT * FROM " + Table + Criteria );
    }
    result = statement.executeQuery(Query);

    int Numrow = 0;
    int Numrow1 = 0;
    int MaxProgress = 100;
    //
    ResultSet rs= statement.getResultSet();
    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    Vector data = new Vector(columnCount);
    Vector row = new Vector(columnCount);
    Vector columnNames = new Vector(columnCount);
    for (int i = 1; i <= columnCount; i++) {
    columnNames.addElement( md.getColumnName(i));
    }
    while (rs.next()) {
    for (int i = 1; i <= columnCount; i++) {
    row.addElement(rs.getObject(i));
    }
    data.addElement(row);
    row = new Vector(columnCount); // Create a new row Vector
    Numrow++;

    }

    DefaultTableModel model = new DefaultTableModel(data, columnNames);
    jTable1.setModel( model );
    jTable1.setSelectionMode(ListSelectionModel.SINGLE _SELECTION);
    jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    jTable1.setDefaultEditor(Object.class, null);
    String header[] = {"Kode Jurnal"};
    for(int i=0;i<jTable1.getColumnCount();i++)
    {
    TableColumn column1 = jTable1.getTableHeader().getColumnModel().getColum n(i);
    column1.setHeaderValue(header[i]);
    column1.setPreferredWidth(100);
    }
    } catch (SQLException sqlex) {
    jLblStatementError.setText(sqlex.toString());
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please help to solve number display in E7

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    display in E7 example 10.000.000 it display as 1E7.
    How are you formatting the number for display? Have you tried the printf() method or the methods of the DecimalFormat class?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help to solve number display in E7

    Hi Norm,
    thank you for your reply. i don't know where to put the format. since the data display on jtable and using looping line. the data display on jtable consist of string and numeric. please help..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please help to solve number display in E7

    If you want to get a String from a number, use the DecimalFormat class method to do the conversion.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2017
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help to solve number display in E7

    Hi Norm, I knew that function but how to apply to my code below?
    int Numrow = 0;
    int Numrow1 = 0;
    int MaxProgress = 100;
    //
    ResultSet rs= statement.getResultSet();
    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    Vector data = new Vector(columnCount);
    Vector row = new Vector(columnCount);
    Vector columnNames = new Vector(columnCount);
    for (int i = 1; i <= columnCount; i++) {
    columnNames.addElement( md.getColumnName(i));
    }
    while (rs.next()) {
    for (int i = 1; i <= columnCount; i++) {
    row.addElement(rs.getObject(i));
    }
    data.addElement(row); ----> this data display here. but how to apply decimal class funcion????
    row = new Vector(columnCount); // Create a new row Vector
    Numrow++;

    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please help to solve number display in E7

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2017
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help to solve number display in E7

    private void GridListing() {
    try {
    statement = DBConnections.getDBConnectionSys().createStatement ();
    if (jSearchBy1.getSelectedItem() == "Kode Jurnal") 
    Criteria = " WHERE journal_no Like '" + jTxtSearch1.getText() + "%'";
    else if (jSearchBy1.getSelectedItem() == "Tanggal Jurnal") 
    Criteria = " WHERE journal_date '" + jTxtSearch1.getText() + "%'";
    //Different DB Different Terms of Syntax
    if (GlobalSettings.dataBaseType == 1 || GlobalSettings.dataBaseType == 2) {
    Query = ("SELECT TOP 100 * FROM " + Table + Criteria); }
    if (GlobalSettings.dataBaseType == 3 || GlobalSettings.dataBaseType == 4) {
    Query = ("SELECT * FROM " + Table + Criteria ); 
    }
    result = statement.executeQuery(Query);
     
    int Numrow = 0;
    int Numrow1 = 0;
    int MaxProgress = 100;
    //
    ResultSet rs= statement.getResultSet();
    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    Vector data = new Vector(columnCount);
    Vector row = new Vector(columnCount);
    Vector columnNames = new Vector(columnCount);
    for (int i = 1; i <= columnCount; i++) {
    columnNames.addElement( md.getColumnName(i));
    }
    while (rs.next()) {
    for (int i = 1; i <= columnCount; i++) {
    row.addElement(rs.getObject(i));
    }
    data.addElement(row);
    row = new Vector(columnCount); // Create a new row Vector
    Numrow++;
     
    }
     
    DefaultTableModel model = new DefaultTableModel(data, columnNames);
    jTable1.setModel( model );
    jTable1.setSelectionMode(ListSelectionModel.SINGLE _SELECTION);
    jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    jTable1.setDefaultEditor(Object.class, null);
    String header[] = {"Kode Jurnal"}; 
    for(int i=0;i<jTable1.getColumnCount();i++) 
    { 
    TableColumn column1 = jTable1.getTableHeader().getColumnModel().getColum n(i); 
    column1.setHeaderValue(header[i]); 
    column1.setPreferredWidth(100);
    } 
    } catch (SQLException sqlex) {
    jLblStatementError.setText(sqlex.toString());
    }
    }

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please help to solve number display in E7

    What variable has the numeric value you want to format?
    Where is that variable's value converted to a String to be displayed?


    Note: The code in post#7 has lost all its indentations making it harder to read and understand. Please try to preserve code's formatting when posting it.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Sep 2017
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help to solve number display in E7

    Hi Norm, please apologize hehe here the better one
      private void GridListing() {
            try {
                            statement = DBConnections.getDBConnectionSys().createStatement();
                            if (jSearchBy1.getSelectedItem() == "Kode Jurnal")  
                                    Criteria = " WHERE journal_no Like '" + jTxtSearch1.getText() + "%'";
                            else if (jSearchBy1.getSelectedItem() == "Tanggal Jurnal")  
                                    Criteria = " WHERE journal_date '" + jTxtSearch1.getText() + "%'";
                //Different DB Different Terms of Syntax
                if (GlobalSettings.dataBaseType == 1 || GlobalSettings.dataBaseType == 2) {
                    Query = ("SELECT  TOP 100 * FROM " + Table + Criteria); }
                if (GlobalSettings.dataBaseType == 3 || GlobalSettings.dataBaseType == 4) {
                    Query = ("SELECT  * FROM " + Table + Criteria ); 
                }
                result = statement.executeQuery(Query);
     
                int Numrow = 0;
                int Numrow1 = 0;
                int MaxProgress = 100;
                //
                ResultSet rs= statement.getResultSet();
                ResultSetMetaData md = rs.getMetaData();
                int columnCount = md.getColumnCount();
                Vector data = new Vector(columnCount);
                Vector row = new Vector(columnCount);
                Vector columnNames = new Vector(columnCount);
                for (int i = 1; i <= columnCount; i++) {
                    columnNames.addElement( md.getColumnName(i));
                }
                while (rs.next()) {
                    for (int i = 1; i <= columnCount; i++) {
                        row.addElement(rs.getObject(i));
                    }
                    data.addElement(row);
                    row = new Vector(columnCount); // Create a new row Vector
                    Numrow++;
     
                }
                TableColumnModel m = jTable1.getColumnModel();
                m.getColumn(8).setCellRenderer(NumberRenderer.getCurrencyRenderer());
                DefaultTableModel model = new DefaultTableModel(data, columnNames);
                jTable1.setModel( model );
                jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                jTable1.setDefaultEditor(Object.class, null);
                String header[] = {"Tipe Jurnal"};  
                for(int i=0;i<jTable1.getColumnCount();i++)  
                {  
                TableColumn column1 = jTable1.getTableHeader().getColumnModel().getColumn(i);  
                column1.setHeaderValue(header[i]);  
                column1.setPreferredWidth(100);
                }   
            } catch (SQLException sqlex) {
                jLblStatementError.setText(sqlex.toString());
            }
        }

    at the column index of 8 should be numeric, the rest are string.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please help to solve number display in E7

    Much better formatting for the posted code.

    column index of 8 should be numeric, the rest are string.
    Can you make them all String and apply formatting to column 8 to display the numbers as desired?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Sep 2017
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help to solve number display in E7

    Hi Norm,
    after i post this forum and with help of your suggestion . suddenly googling at this website
    https://tips4java.wordpress.com/2008...mat-renderers/

    and everything is solved. thank you very much....

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please help to solve number display in E7

    Glad you got it working.

    Thanks for posting the link about renderers.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] ARRAYs - Display number of students who failed
    By roronoaz in forum Java Theory & Questions
    Replies: 6
    Last Post: July 2nd, 2012, 09:51 AM
  2. display all prime factors of a number
    By mia_tech in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 18th, 2012, 06:55 PM
  3. Display number of threads in each running process
    By Waseem Usman in forum Threads
    Replies: 1
    Last Post: March 23rd, 2012, 09:51 AM
  4. display the generated Math.random number
    By PsYNus in forum What's Wrong With My Code?
    Replies: 11
    Last Post: November 2nd, 2011, 10:25 AM
  5. How to display the results + repeat to the number entered by user?
    By TheBattousaixx in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 17th, 2011, 11:56 PM