I have posted part of my code which is sufficient to solve my problem.I want to blink a row when condition is met. If in case that condition is met in multiple rows, then all that rows should blink.
I tried but I could blink only one row at a time. Please help me.
//-------------------table------------------------
p32 = new JPanel();
p32.setBackground(Color.WHITE);
p32.setLayout(new BorderLayout());
String[] columnNames = {"Component Name", "Life Period", "Last Date" };
Object[][] data =
{
};
model = new DefaultTableModel(data,columnNames);
table = new JTable(model);
table.setRowHeight(50);
table.getTableHeader().setPreferredSize(new Dimension(50,50));
table.getTableHeader().setFont(new Font("Dialog", Font.BOLD, 20));
table.getTableHeader().setBackground(Color.BLUE);
table.getTableHeader().setForeground(Color.WHITE);
table.setFont(new Font("Times New Roman",Font.PLAIN,20));
table.setBackground(Color.white);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.getViewport().setBackground(new Color(201,204,255));
p32.add(scrollPane,"Center");
//---button panel---
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
addButton = new JButton("ADD");
addButton.setPreferredSize(new Dimension(100,50));
deleteButton = new JButton("DELETE");
deleteButton.setPreferredSize(new Dimension(100,50));
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
JPanel panel = new JPanel();
JTextField t1 = new JTextField(10);
t1.setHorizontalAlignment(JTextField.CENTER);
JTextField t2 = new JTextField(10);
t2.setHorizontalAlignment(JTextField.CENTER);
panel.add(new JLabel("Component "));
panel.add(t1);
panel.add(Box.createHorizontalStrut(5));
panel.add(new JLabel("Period "));
panel.add(t2);
JOptionPane.showConfirmDialog(f,panel,"Enter values",JOptionPane.PLAIN_MESSAGE);
if((!t1.getText().equals(""))&&(!t2.getText().equals("")))
{
boolean isInteger = isInteger(t2.getText());
if(isInteger)
{
int i = Integer.parseInt(t2.getText());
sdf = new SimpleDateFormat("yyyy-MM-dd");
calendar1 = Calendar.getInstance();
calendar1.setTime(new Date());
calendar1.add(Calendar.DATE,i);
last_date = sdf.format(calendar1.getTime());
model.addRow(new Object[]{t1.getText(),t2.getText(),last_date});
}
}
}
});
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
int row = table.getSelectedRow();
while(row != -1)
{
int modelRow = table.convertRowIndexToModel(row);
model.removeRow(modelRow);
row = table.getSelectedRow();
}
}
});
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridy = 0;
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.insets = new Insets(0,10,0,10);
buttonPanel.add(addButton,gbc);
gbc.gridy = 1;
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
gbc.insets = new Insets(0,10,0,10);
buttonPanel.add(deleteButton,gbc);
p32.add(buttonPanel,"East");
//---------------------------------------------------------------
public void maintenance(){
Timer timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//-----code------
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment( JLabel.CENTER );
table.setDefaultRenderer(Object.class, centerRenderer);
for(int r = 0; r < table.getRowCount(); r++)
{
String last_date = model.getValueAt(r, 2).toString();
String pres_date = sdf.format(new Date());
if(pres_date.equals(last_date)){
//--Blink that particular row---
}
}
//-------------
}
});
timer.start();
}
//-----------------------
Comments
Post a Comment