How to use Up/Down Arrow Key in Java Tutorial Using Netbeans IDE

How to use Up/Down Arrow Key in Java Tutorial Using Netbeans IDE

This tutorial is all about How to use Up/Down Arrow Key in Java Tutorial Using Netbeans IDE. In this tutorial you will learn how to select a record in JTable using the Up and Down Arrow Keys in java and automatically setting the data to the textfield. This tutorial uses Key Event Package library, JTable, JTextField Componenents and Netbeans IDE. Please follow all the steps below to complete this tutorial.

How to use Up/Down Arrow Key in Java Tutorial Using Netbeans IDE

 

Create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. After that you create a class by right clicking the source packages and new java class. You can name your class whatever you want.

And then you need to import the package import com.sun.glass.events.KeyEvent; above your class. The next step is to right click your JTable and click Events / Key / keyReleased , and then copy the code below and paste it inside the keyReleased Event.

[java]

if((evt.getKeyCode()==KeyEvent.VK_UP) || (evt.getKeyCode() == KeyEvent.VK_DOWN)){

try{

int row = productTable.getSelectedRow();

String click = (productTable.getModel().getValueAt(row, 0).toString());

String sql = “SELECT YourColumnInDatabase FROM YourTable WHERE ColumnName='”+click+”‘”;

pst = conn.prepareStatement(sql);

rs = pst.executeQuery();

if(rs.next()){

//This is the JTextField

productNameTxt.setText(rs.getString(“product_name”));

companyNameTxt.setText(rs.getString(“company_name”));

productCategoryTxt.setText(rs.getString(“product_category”));

}

}catch(Exception e){

JOptionPane.showMessageDialog(null, e);

}

}

[/java]

 

Then you’re done. Run your project and see if it works.

About How to use Up/Down Arrow Key In Java

Project Name: How to use Up/Down Arrow Key
Language/s Used: JAVA
Database: MySQL
Type: Desktop Application
Developer: IT SOURCECODE
Updates: 0
How to use Up/Down Arrow Key In Java– Project Information

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]

Facebook: facebook.com/RyyanSalem

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

System Analyst / System Developer

Related topic(s) that you make like:

1.) Createa MySQL Connection in Java
2.) Automated Payroll System using java Netbeans IDE

 

 

Leave a Comment