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.
Java JButton below the JTable: How to use and place JButton just under or beneath the JTable.
Here 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
Theme Pilcrow by Automattic CSS Edit: How to edit the CSS style sheet to fit the size of your custom header?
Yesterday while visiting the forum I found another WordPress blogger, who was using theme Pilcrow by Automattic, faced problem to edit the CSS to use Custom header in her blog. She tried a lot to implement and use her Custom header in the blog by using CSS but didn’t get success. While examining her CSS code I found she did a little mistake for which her favorite custom header was not appearing in her blog. Actually the header Width and Height was 800 x 300 px, I found that in her CSS she used Width:800 px but she did mistake in the height value which she used was Height :3px (wrong value, it should be 300px). So, if you have purchased CSS upgrade from WordPress and using Pilcrow theme and want to change the header of your theme, just use the following code: Continue reading “Theme Pilcrow by Automattic CSS Edit: How to edit the CSS style sheet to fit the size of your custom header?”
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.
In 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.
JTable Cell Edit for validation: How to assign two Different JTextField in two different JTable Column Cells.
This 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.
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.
Continue reading “Java JTable Cell and JTextField: How to use and assign JTextField in JTable cell.”
JTable Cell Validation: How to make JTable Cell allow or accept only integer (numeric) number/data.
Sometimes 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.
Here 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.
Continue reading “JTable cell Color: How to color your JTable individual cell background.”
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] ;
Continue reading “JTable Cell Click Event: Click on the JTable Cell and show the Value of that cell.”
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:

