Rabu, 18 Mei 2016

Java Swing (GUI) Programming: From Beginner to Expert

Use This Coupon Code 50% Off = LEARN058

                            
                           Watch The Course Introduction


                       
           Instructor : John Purcell
           Lectures   : 93
           Hours        : 14
           Students   > 7.000

Learn how to create desktop and Internet GUI Java programs and take your Java programming to the next level.


Course Description

This course teaches you how to create desktop and web-based applications using Java Swing, Java's built-in user interface toolkit.
Among other things we'll look at nearly all Swing widgets, we'll take a look at JDBC for database access, the graphics API, model-view-controller (MVC) architecture, serialization for saving data, the listener-event model and even basic animation.
Use This Coupon Code 50% Off = LEARN058

Baca selengkapnya

The Complete Web Developer Course 2.0

Use This Coupon Code 50% Off = LEARN058

                               
                           Watch The Course Introduction


                       
           Instructor : Rob Percival
           Lectures   : 288
           Hours        : 30.5
           Students   > 20.000

Learn By Doing - build 25 websites and real mobile apps


  • How does the web work?
  • Setting up your (free) hosting
  • HTML
  • CSS
  • Javascript
  • jQuery
  • CMSs and WordPress
  • Responsive Design
  • PHP Coding
  • MySQL Databases
  • Putting it all together: Making a Twitter clone


Use This Coupon Code 50% Off = LEARN058


Baca selengkapnya

Minggu, 01 Mei 2016

VB.NET - How To Change A DataGridView Row Color In VB

VB - How To Change A DataGridView Row Back Color In VB.NET


vb change datagridview row color


In This VB.NET Tutorial We Will See How To  Cahange A DataGridView Row BackGround Color Based On A Column Value In VB.NET Programming Language .


Project Source Code:



Public Class VB_Datagridview_Rows_Color
' Create a new datatable
Dim table As New DataTable("Table")
Private Sub VB_Datagridview_Rows_Color_Load(sender As Object, e As EventArgs) Handles MyBase.Load

' Add columns to your datatable,
' with the name of the columns and their type


table.Columns.Add("Id", Type.GetType("System.Int32"))
table.Columns.Add("First Name", Type.GetType("System.String"))
table.Columns.Add("Last Name", Type.GetType("System.String"))
table.Columns.Add("Age", Type.GetType("System.Int32"))

' Add rows to the datatable with some data
table.Rows.Add(1, "XXXX", "YYYYY", 21)
table.Rows.Add(2, "SSDD", "hGSQ", 5)
table.Rows.Add(4, "cvfghyghj", "sdrgtyh", 19)
table.Rows.Add(5, "hghfd", "ghjgdf", 36)
table.Rows.Add(6, "cvvdfgh", "juyrfdvc", 3)
table.Rows.Add(1, "XXXX", "YYYYY", 0)
table.Rows.Add(2, "SSDD", "hGSQ", 12)
table.Rows.Add(3, "fgfgd", "jgfdd", 0)
table.Rows.Add(4, "cvfghyghj", "sdrgtyh", 9)
table.Rows.Add(5, "hghfd", "ghjgdf", 1)
table.Rows.Add(6, "cvvdfgh", "juyrfdvc", 32)
table.Rows.Add(1, "XXXX", "YYYYY", 7)
table.Rows.Add(2, "SSDD", "hGSQ", 1)
table.Rows.Add(3, "fgfgd", "jgfdd", 14)
table.Rows.Add(4, "cvfghyghj", "sdrgtyh", 0)
table.Rows.Add(5, "hghfd", "ghjgdf", 33)
table.Rows.Add(6, "cvvdfgh", "juyrfdvc", 21)
table.Rows.Add(1, "XXXX", "YYYYY", 2)
table.Rows.Add(2, "SSDD", "hGSQ", 18)
table.Rows.Add(3, "fgfgd", "jgfdd", 45)
table.Rows.Add(4, "cvfghyghj", "sdrgtyh", 4)


' now set the datagridview datasource equals to your datatable name
DataGridView1.DataSource = table


RowsColor()
End Sub

Public Sub RowsColor()

For i As Integer = 0 To DataGridView1.Rows.Count() - 1 Step +1
Dim val As Integer
val = DataGridView1.Rows(i).Cells(3).Value
If val < 5 Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Red
If val = 0 Then
Timer1.Start()
End If
ElseIf val >= 5 And val < 10 Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Orange
ElseIf val >= 10 And val < 15 Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Yellow
Else
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
End If
Next
End Sub

' if val = 0
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
For i As Integer = 0 To DataGridView1.Rows.Count() - 1 Step +1
Dim val As Integer
val = DataGridView1.Rows(i).Cells(3).Value
If val = 0 Then
If DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Red Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.White
ElseIf DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.White Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Red
End If
End If
Next
End Sub
End Class


///////////////OUTPUT:

vb change datagridview row back color
vb change datagridview row back color

Baca selengkapnya

Java JTable - How To Get JTable Column Average Value In Java NetBeans

How To Calculate JTable Column Average Value In Java 

jtable average column value

In this java Tutorial we will see How To Calculate JTable Column Average Value And Display It In JTextFields In Java NetBeans .

*Java Courses Java Complete Course
                            Java Swing Course


Project Source Code:

package java_tutorials;

/**
 *
 * @author 1BestCsharp
 */
public class Java_JTable_Column_Average_Value extends javax.swing.JFrame {

    /**
     * Creates new form Java_JTable_Column_Average_Value
     */
    public Java_JTable_Column_Average_Value() {
        initComponents();
        getAverage();
    }

    
    public void getAverage()
    {
        float sum = 0;
        for(int i = 0; i < jTable1.getRowCount(); i++)
        {
            sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());
        }
        
        float avg = sum / jTable1.getRowCount();
        jTextField1.setText(Float.toString(avg));
    }
    
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"1", "dcd", "ABC", "42"},
                {"2", "ss", "rtyh", "14"},
                {"3", "fs", "jhg", "62"},
                {"4", "ynjhdg", "fg", "14"},
                {"5", "uyt", "èiuy", "17"},
                {"6", "nb", "oop", "26"},
                {"7", "yui", "lkjh", "27"},
                {"8", "rtyu", "jhg", "39"},
                {"9", "jhgf", "dfg", "56"},
                {"10", "gdsfe", "èiuytre", "46"}
            },
            new String [] {
                "Id", "First Name", "Last Name", "Age"
            }
        ));
        jTable1.setRowHeight(30);
        jScrollPane1.setViewportView(jTable1);

        jTextField1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Avg :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Average_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Average_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Average_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Average_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_JTable_Column_Average_Value().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   
}



////////////////OutPut

jtable column average value
JTable Average Column Value

Baca selengkapnya

Java JTable - How To Get JTable Column Maximum Value In Java NetBeans

How To Calculate JTable Column Max Value In Java NetBeans

jtable maximum column value

In this java Tutorial we will see How To Calculate JTable Column Max Value And Display It In JTextFields In Java NetBeans .

*Java Courses Java Complete Course
                            Java Swing Course


Project Source Code:

package java_tutorials;

import java.util.ArrayList;
import java.util.Collections;

/**
 *
 * @author 1BestCsharp
 */
public class Java_JTable_Column_Max_Value extends javax.swing.JFrame {

    /**
     * Creates new form Java_JTable_Column_Max_Value
     */
    public Java_JTable_Column_Max_Value() {
        initComponents();
        getMax2();
    }

    // Method 1
    public void getMax()
    {
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int i = 0; i < jTable1.getRowCount(); i++)
        {
            list.add(Integer.parseInt(jTable1.getValueAt(i, 3).toString()));
        }
        
        int max = Collections.max(list);
        jTextField1.setText(Integer.toString(max));
    }
    
// Method 2
    public void getMax2()
    {
        int max2 = 0;
        
        for(int i = 0; i < jTable1.getRowCount(); i++)
        {
          int val = Integer.parseInt(jTable1.getValueAt(i, 3).toString());
          if(val > max2)
          {
              max2 = val;
          }
        }
         jTextField1.setText(Integer.toString(max2));
    }
    
    
    
    
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"1", "dcd", "ABC", "42"},
                {"2", "ss", "rtyh", "14"},
                {"3", "fs", "jhg", "62"},
                {"4", "ynjhdg", "fg", "14"},
                {"5", "uyt", "èiuy", "17"},
                {"6", "nb", "oop", "26"},
                {"7", "yui", "lkjh", "27"},
                {"8", "rtyu", "jhg", "39"},
                {"9", "jhgf", "dfg", "56"},
                {"10", "gdsfe", "èiuytre", "46"}
            },
            new String [] {
                "Id", "First Name", "Last Name", "Age"
            }
        ));
        jTable1.setRowHeight(30);
        jScrollPane1.setViewportView(jTable1);

        jTextField1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Max :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Max_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Max_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Max_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Max_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_JTable_Column_Max_Value().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   
}


////////////////OutPut
jtable maximum column value
jtable maximum column value


Baca selengkapnya

Java JTable - How To Get JTable Column Minimum Value In Java NetBeans

How To Calculate JTable Column Min Value In Java NetBeans

jtable minimum column value

In this java Tutorial we will see How To Calculate JTable Column Min Value And Display It In JTextFields In Java NetBeans .

*Java Courses Java Complete Course
                            Java Swing Course


Project Source Code:

package java_tutorials;

import java.util.ArrayList;
import java.util.Collections;

/**
 *
 * @author 1BestCsharp
 */
public class Java_JTable_Column_Min_Value extends javax.swing.JFrame {

    /**
     * Creates new form Java_JTable_Column_Min_Value
     */
    public Java_JTable_Column_Min_Value() {
        initComponents();
        getMin2();
    }
    
    // Methode 1
    public void getMin()
    {
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i = 0; i < jTable1.getRowCount(); i++)
        {
            list.add(Integer.parseInt(jTable1.getValueAt(i, 3).toString()));
        }
        
        int min = Collections.min(list);
        jTextField1.setText(Integer.toString(min));
    }
    
    // Methode 2
    public void getMin2()
    {
        int min2 = 0;
        for(int i = 0; i < jTable1.getRowCount(); i++)
        {
            if(i == 0)
            {
                min2 = Integer.parseInt(jTable1.getValueAt(i, 3).toString());
            }
            else{
                int val = Integer.parseInt(jTable1.getValueAt(i, 3).toString());
                if(min2 > val)
                {
                    min2 = val;
                }
            }
        }
         jTextField1.setText(Integer.toString(min2));
        
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"1", "dcd", "ABC", "42"},
                {"2", "ss", "rtyh", "14"},
                {"3", "fs", "jhg", "62"},
                {"4", "ynjhdg", "fg", "14"},
                {"5", "uyt", "èiuy", "17"},
                {"6", "nb", "oop", "26"},
                {"7", "yui", "lkjh", "27"},
                {"8", "rtyu", "jhg", "39"},
                {"9", "jhgf", "dfg", "56"},
                {"10", "gdsfe", "èiuytre", "46"}
            },
            new String [] {
                "Id", "First Name", "Last Name", "Age"
            }
        ));
        jTable1.setRowHeight(30);
        jScrollPane1.setViewportView(jTable1);

        jTextField1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Min :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Min_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Min_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Min_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Min_Value.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_JTable_Column_Min_Value().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   
}


////////////////OutPut
jtable column minimum  value
Java JTable Minimum Column Value


Baca selengkapnya

Java JTable - How To Get The Sum Of JTable Column Values In Java NetBeans

How To Calculate JTable Column Values Sum In Java

jtable column values sum

In this java Tutorial we will see How To Calculate JTable Column Values Sum And Display It In JTextFields In Java NetBeans .

*Java Courses Java Complete Course
                            Java Swing Course


Project Source Code:

package java_tutorials;

/**
 *
 * @author 1BestCsharp
 */
public class Java_JTable_Column_Values_Sum extends javax.swing.JFrame {

    /**
     * Creates new form Java_JTable_Column_Values_Sum
     */
    public Java_JTable_Column_Values_Sum() {
        initComponents();
        // cal get sum function
        getSum();
    }

    
    public void getSum()
    {
        int sum = 0;
        for(int i = 0; i < jTable1.getRowCount(); i++)
        {
            sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());
        }
        
        jTextField1.setText(Integer.toString(sum));
    }
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"1", "dcd", "ABC", "42"},
                {"2", "ss", "rtyh", "14"},
                {"3", "fs", "jhg", "62"},
                {"4", "ynjhdg", "fg", "14"},
                {"5", "uyt", "èiuy", "17"},
                {"6", "nb", "oop", "26"},
                {"7", "yui", "lkjh", "27"},
                {"8", "rtyu", "jhg", "39"},
                {"9", "jhgf", "dfg", "56"},
                {"10", "gdsfe", "èiuytre", "46"}
            },
            new String [] {
                "Id", "First Name", "Last Name", "Age"
            }
        ));
        jTable1.setRowHeight(30);
        jScrollPane1.setViewportView(jTable1);

        jTextField1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Sum :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39))
        );

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Values_Sum.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Values_Sum.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Values_Sum.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Column_Values_Sum.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_JTable_Column_Values_Sum().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   
}

////////////////OutPut

java jtable column values sum
java jtable column values sum

Baca selengkapnya