Java Add Node To JTree

How To Add A New Node To JTree Using Java NetBeans

insert new node to jtree



In this Java Tutorial we will see How To Insert A New Node To JTree From JTextField Using DefaultMutableTreeNode + TreeSelectionModel On Button Click Event In Java NetBeans .




Project Source Code:

private void jButtonAddNodeActionPerformed(java.awt.event.ActionEvent evt) {                                               
        
        // get selected Node
        
        TreeSelectionModel smd = jTree1.getSelectionModel();
        
        if(smd.getSelectionCount() > 0){
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();

            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(jTextField1.getText());

            selectedNode.add(newNode);

            DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();

            model.reload();
        }
    }  


OutPut:

insert new node to jtree using java




Java Import Text File Data To JTable

How To Populate JTable From Txt File Text Using Java NetBeans

Import Txt File Data To JTable Using Java



In this Java Tutorial we will see How To Import Text From Text File And Set It Into JTable Rows Using BufferedReader +  DefaultTableModel On JButton Click In Java programming language and NetBeans IDE .




Project Source Code:

private void jButtonImportActionPerformed(java.awt.event.ActionEvent evt) {                                              
        
        String filePath = "C:\\Users\\Desktop\\table.txt";
        File file = new File(filePath);
        
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            // get the first line
            // get the columns name from the first line
            // set columns name to the jtable model
            String firstLine = br.readLine().trim();
            String[] columnsName = firstLine.split(",");
            DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
            model.setColumnIdentifiers(columnsName);
            
            // get lines from txt file
            Object[] tableLines = br.lines().toArray();
            
            // extratct data from lines
            // set data to jtable model
            for(int i = 0; i < tableLines.length; i++)
            {
                String line = tableLines[i].toString().trim();
                String[] dataRow = line.split("/");
                model.addRow(dataRow);
            }
            
            
        } catch (Exception ex) {
            Logger.getLogger(TextFileDataToJTable.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 


OutPut:

Populate JTable Using Text File Text In Java



VB.Net Move Element Inside The Form

How To Move Object Around The Form In Visual Basic.Net 

vb.net move object inside the form

In This VB.Net Tutorial  We Will See How To Move Panel UP, RIGHT, DOWN, LEFT In The Form By Pressing Arrow Keys Using Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class Moving_Element

    Private Sub Moving_Element_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown

        Select Case e.KeyCode
            ' move up
            Case Keys.Up
                Panel1.Location = New Point(Panel1.Location.X, Panel1.Location.Y - 1)
            ' move down
            Case Keys.Down
                Panel1.Location = New Point(Panel1.Location.X, Panel1.Location.Y + 1)
            ' move right
            Case Keys.Right
                Panel1.Location = New Point(Panel1.Location.X + 1, Panel1.Location.Y)
             ' move left
            Case Keys.Left
                Panel1.Location = New Point(Panel1.Location.X - 1, Panel1.Location.Y)

        End Select

    End Sub
End Class
      
///////////////OUTPUT:





vbnet moving element



Javascript Search Item Position In A MultiDimensional Array

How To Get Value Position In A 2D Array Using Javascript 

Javascript Search Item Position In A MultiDimensional Array


In This Javascript Tutorial we will See How To Search Data In A Multi-Dimensional And Get The Data Positions In The 2D Array Using For Loop Using JS And Netbeans Editor .


Project Source Code:

    <!DOCTYPE html>
<html>
    <head>
        <title>Javascript: search in multidimensional array</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        
        <p id="txt"></p>
        
        <script>
            
            var ar = [
                       ["A1","B1","B5","D1"],//0
                       ["A2","B2","C2","B5"],//1
                       ["B5","B3","B5","D3"],//2
                       ["A4","B4","C4","B5"],
                       ["A5","B5","C5","D5"]
            ], txt = document.getElementById("txt"), data = "";
            
            for(var i = 0; i < ar.length; i++){// lines
                
                for(var j = 0; j < ar[i].length; j++){ // columns
                    data = data + ar[i][j]+" , ";
                    if(ar[i][j] === "B5"){
                        console.log("POSITION[ " + i + " , " + j +" ]")
                    }
                    
                }
                data = data + "<br>";
            }
            txt.innerHTML = data;
           
         </script>   
        
    </body>
</html>




OUTPUT:



search in multidimensional array In JS

VB.Net KeyCode

VB NET Using Key Code

vb.net KeyCode

In This VB.Net Tutorial  We Will See How To Use KeyCode On KeyDown To Check Which Key Is Pressed Like ENTER or SPACE In Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class Form_Key_Code

    Private Sub Form_Key_Code_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown

        Dim code As String
        code = e.KeyCode

        Select Case code

            Case 32
                Label1.Text = "Spacebar"

            Case 13
                Label1.Text = "Enter"

        End Select

    End Sub
End Class
      
///////////////OUTPUT:

vbnet keycode enter

vbnet keycode spacebar




VB.Net KeyChar

VBNET Using Key Char

VBnet Key Char

In This VB.Net Tutorial  We Will See How To Use KeyChar On KeyPress To Check Which Key Is Pressed Like ENTER or SPACE In Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class Form_key_char


    Private Sub Form_key_char_KeyPress(sender As Object, e As KeyPressEventArgs) Handles MyBase.KeyPress

        Dim ch As String
        ch = e.KeyChar

        Label1.Text = ch

        Select Case ch

            Case Convert.ToChar(Keys.Enter)
                Label1.Text = "Enter"

            Case Convert.ToChar(Keys.Space)
                Label1.Text = "Space"

        End Select

    End Sub
End Class
      
///////////////OUTPUT:
vbnet enter key press

vbnet spacebar key press




C# KeyChar, KeyCode

How To Use Key Char And Key Code In C#

C# Key Char & Key Code


In This C# Tutorial  We Will See How To Use KeyChar And KeyCode To Check Which Key Is Pressed ENTER or SPACE, SHIFT... In CSharp Programming Language And Visual  Studio Editor.


Project Source Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Csharp_keycode_keychar : Form
    {
        public Csharp_keycode_keychar()
        {
            InitializeComponent();
        }

// keycode
        private void Csharp_keycode_keychar_KeyDown(object sender, KeyEventArgs e)
        {

            if ((e.KeyCode == Keys.Enter) && e.Control)
                label1.Text = "CONTROL + ENTER";
            else
                label1.Text = "/////";

        }

// keychar
        private void Csharp_keycode_keychar_KeyPress(object sender, KeyPressEventArgs e)
        {
            
            if(e.KeyChar == (char)Keys.Space)
                label1.Text = "spacebar";
            else
                label1.Text = "/////";
           
        }
    }
}



// OUTPUT :

c# enter key keychar




Javascript - HTML Table Maximum Minimum Sum Average Value

How To Get HTML Table Column Max, Min, Sum, Avg Value In Javascript  

HTML Table Column Max, Min, Sum, Avg Value In Javascript


In This Javascript Tutorial we will See How To Find The Maximum,  Minimum Value And Calculate The Sum And Average Value Of An HTML Table Column using JS And Netbeans Editor .


Project Source Code:


<!DOCTYPE html>

<html>
    <head>
        <title>Javascript HTML Table - Min Max Sum Avg</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        
        <table id="table" border="1">
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Value</th>
            </tr>
            <tr>
                <td>A1</td>
                <td>B1</td>
                <td>43</td>
            </tr>
            <tr>
                <td>A2</td>
                <td>B2</td>
                <td>28</td>
            </tr>
            <tr>
                <td>A3</td>
                <td>B3</td>
                <td>15</td>
            </tr>
            <tr>
                <td>A4</td>
                <td>B4</td>
                <td>50</td>
            </tr>
            <tr>
                <td>A5</td>
                <td>B5</td>
                <td>31</td>
            </tr>
            <tr>
                <td>A6</td>
                <td>B6</td>
                <td>85</td>
            </tr>
            <tr>
                <td>A7</td>
                <td>B7</td>
                <td>18</td>
            </tr>
        </table>
        
        <span id="minV"></span><br>
        <span id="maxV"></span><br>
        <span id="sumV"></span><br>
        <span id="avgV"></span>
        
        <script>
            
            var table = document.getElementById("table"), sumVal = 0;

            getMin();
            getMax();
            getSum();
            getAvg();

           // get min value
            function getMin()
            {
              var minVal, minIndex;
              for(var i = 1; i < table.rows.length; i++){
                  if(i === 1){
                      minVal = table.rows[i].cells[2].innerHTML;
                      minIndex = table.rows[i].rowIndex;
                  }else if(minVal > table.rows[i].cells[2].innerHTML){
                      minVal = table.rows[i].cells[2].innerHTML;
                      minIndex = table.rows[i].rowIndex;
                  }
              }
              table.rows[minIndex].cells[2].style.background = "red";
              table.rows[minIndex].cells[2].style.color = "white";
              document.getElementById("minV").innerHTML = "Minimum Value = "+minVal;
              document.getElementById("minV").style.color = "red";
               console.log("Min => "+minVal);       
            }
            

            // get max value
            function getMax()
            {
              var maxVal, maxIndex;
              for(var i = 1; i < table.rows.length; i++){
                  if(i === 1){
                      maxVal = table.rows[i].cells[2].innerHTML;
                      maxIndex = table.rows[i].rowIndex;
                  }else if(maxVal < table.rows[i].cells[2].innerHTML){
                      maxVal = table.rows[i].cells[2].innerHTML;
                       maxIndex = table.rows[i].rowIndex;
                  }
              }
              table.rows[maxIndex].cells[2].style.background = "green";
              table.rows[maxIndex].cells[2].style.color = "white";
              document.getElementById("maxV").innerHTML = "Maximum Value = "+maxVal;
              document.getElementById("maxV").style.color = "green";
               console.log("Max => "+maxVal);       
            }
            
            // caculate total/sum value
            function getSum()
            {
              for(var i = 1; i < table.rows.length; i++){
                     sumVal = sumVal + parseInt(table.rows[i].cells[2].innerHTML);
              }
              document.getElementById("sumV").innerHTML = "Sum Value = "+sumVal;
               console.log("Sum => "+sumVal);       
            }
            
            // caculate avg value
            function getAvg()
            {
                var avg = sumVal / (table.rows.length - 1);// minus the header
                document.getElementById("avgV").innerHTML = "Average Value = "+parseInt(avg);
                console.log("Avg => "+parseInt(avg));
            }
            
        </script>
        
    </body>
</html>




OUTPUT:


Javascript Min Max Sum Avg Values