Java String Manipulation: How to search or match any given word in a string and then replace that word


search a word in a string and then replace javaHere, I am sharing you another basic technique about java where I have searched a word in a String and then replace it by another word. In this technique I have avoided case differences (avoiding upper case or lower case letter difference). From this example you will be able to know about

  1. How to search any specific word in a string
  2. 

  3. How to avoid case difference  while searching a word in a string using java
  4. How to replace any specific word ignoring case difference.

 

Read more of this post

Java JButton Click event and JTable: Click on the JButton and the JTable will show or appear


Here I am sharing you a simple but useful way about JButton and JTable. Sometimes in designing   software, where we are using JButton and JTable, we may need to code or design in such a way that just user will click on the JButton (by using JButton ActionListener) and the JTable will show or appear with its value. Copy the code below and run on your computer.

Read more of this post

Java JButton below the JTable: How to use and place JButton just under or beneath the JTable.


JBUtton below the JTableHere I am sharing with you another simple but important  fact related to  java JTable and JButton. If you are using JButton and JTable in your software, it may need to place your JButton just under or below the JTable. Here I have shown the way how to place JButton just beneath the JTable. Just copy the code below and run in your pc.

Here is the Code:   JButton Just Below or beneath the JTable

Read more of this post

JTable Cell Validation: How to make Cells of first Column will take Char (string)input other Cells of second column will take int (integer ) input.


Two different JTable Cell two different inputIn my last post  I shared  about how to assign two different JTextField in two different JTable Column cells. Today I am sharing with you  another important part of  JTable cell validation where I have tried to show you about how to make  first column of JTable cells take only Char or string input and also at the same time  how to make the  cells second column  take int (integer ) input from the users. To implement this validation process I have assigned two different JTextField in two different JTable Cell Column. Just Copy the following code and Run it in your pc.

Read more of this post

JTable Cell Edit for validation: How to assign two Different JTextField in two different JTable Column Cells.


Two JTextField in two different Table Column cellThis post is also related to JTable cell validation, suppose our JTable has 3 columns.  First column will take String or character type input and the second column or Column 2 will take integer type input from users. So, if we want to implement this scenario in our software we can solve it by assigning or using two different JTextField  for the cells of  Column 1 and Column 2 in JTable. In our example we used textBox1 (JTextField) in Column 1, which will  validate string or char type input from users and  for Column 2  I have assigned    textBox (JTextField) to validate int type input from the users.  The given solution is just a basic you can implement it as your own way.  Just Copy the following code and run it.

 

Read more of this post

Java JTable Cell and JTextField: How to use and assign JTextField in JTable cell.


I think, to assign a JTextField in JTable cells is really important for the purpose of JTable cell validation. For many purpose in software development where we use JTable may need to use JTable cell validation  and for this validation purpose we may also need to assign and use JTextField in JTable cell. In the given Example, I have assigned and used  a JTextField  in the  Column 2  of the following JTable. Just Copy the code and Run it in your computer.

Read more of this post

JTable Cell Validation: How to make JTable Cell allow or accept only integer (numeric) number/data.


JTable Cell ValidationSometimes in programming while we do our work with JTable cell, we may need to make the JTable cell Such that it will allow or accept only numeric or number type data from users and will not allow any other type of data in that cell. In the following example(Check the picture), I have made the cells of Column-2 such that  they will allow only numeric data and it will show a warning message if   any character or string type entry is detected.  Just Copy the code and run it.

JTable cell Color: How to color your JTable individual cell background.


JTable Individual cell colorHere I am going to share with you a little solution by which you can color the background of individual JTable cell. In the following code I colored the cell’s background in click event i.e when you will click on the JTable Cell the background of that cell will be red. This solution is just to give you a basic idea; you can modify it as your own.  The code is given below.

 

Read more of this post

JTable Cell Click Event: Click on the JTable Cell and show the Value of that cell.


Sometimes while programming we may need to check and show the value of JTable Cell in click event.

Here, in the given example, I did the coding in such a way that while clicking on a cell of  JTable

It will show the value of that JTable cell in MessageDialog Box.

Code Example:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

class SimpleTableTest extends JFrame

                {

private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[3];

private String[][] dataValues=new String[3][3] ;
Read more of this post

Java :How to know in which Row and Column I have clicked on JTable


In this post I have shared you the solution about how to know in which Row and Column of JTable I have clicked.

According to the solution, wherever you have clicked on the JTable the result will be shown using

Message Dialog Box (Check the OUTPUT picture below).

 

Code Example:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

class SimpleTableTest extends JFrame

                {

private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[3];

private String[][] dataValues=new String[3][3] ;

public SimpleTableTest()

    {

setTitle(“JTable Cell Click”);

setSize(300,300);

topPanel= new JPanel();

topPanel.setLayout(new BorderLayout());

getContentPane().add(topPanel);

setDefaultCloseOperation(EXIT_ON_CLOSE);

columnNames=new String[] {“Column 1” , “Column 2” , “Column 3”};

 dataValues = new String[][]   {

                                    {“1″,”2″,”3”},

                                    {“4″,”5″,”6”},

                                    {“7″,”8″,”9″}

                                          };

 TableModel model=new myTableModel();

 table =new JTable( );

 table.setRowHeight(50);

 table.setModel(model);

 scrollPane=new JScrollPane(table);

  topPanel.add(scrollPane,BorderLayout.CENTER);   

  table.addMouseListener(new java.awt.event.MouseAdapter()

            {

public void mouseClicked(java.awt.event.MouseEvent e)

{

int row=table.rowAtPoint(e.getPoint());

int col= table.columnAtPoint(e.getPoint());

JOptionPane.showMessageDialog(null,”You have Clicked on Column :” +(col+1)+ ” : and Row : ” +(row+1));

System.out.println(table.getValueAt(row,col).toString());

}

}

);

}

            public class myTableModel extends DefaultTableModel

                                                {

                                                    myTableModel( )

                                                 {

                                                  super(dataValues,columnNames);

                                                  System.out.println(“Inside myTableModel”);

                                                 }

                                                public boolean isCellEditable(int row,int cols)

                                                 {

                                   return false;                                                                                         

                                                }

                                                }         

            public static void main(String args[])

            {

            SimpleTableTest mainFrame=new SimpleTableTest();

            mainFrame.setVisible(true);

            }         

                 }
OUTPUT:

JTable Row and Column Click