Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4078530
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:41:09+00:00 2026-05-20T17:41:09+00:00

I have a Jtable with a checkbox in first column. I want to strikethrough

  • 0

I have a Jtable with a checkbox in first column. I want to strikethrough text of a row when the checkbox is selected. (eg same as we do in microsoft outlook when our task is complete.) I have tried using AttributeString, but not able to do it.

Can anyone please guide me to solve it?

String strStrike; 
AttributedString as; 

public void setTextStrikeThrough() {
    for(int r=0;r< taskcells.length;r++) {
        if (ttable.getValueAt(r,0).equals(Boolean.TRUE)) { 
            for(int c=2;c<7;c++) {
                strStrike+=taskcells[r][c-1]; 
            }//end inner for as=new
            AttributedString(strStrike); 
            as.addAttribute(TextAttribute.STRIKETHROUGH,
                TextAttribute.STRIKETHROUGH_ON);
            as.getIterator(); 
        }//end if 
    }//end for       
}

I am not getting exactly where to call this method. I want to strikethrough text of a row when checkbox of that row has been checked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:41:10+00:00Added an answer on May 20, 2026 at 5:41 pm

    I don’t know that an ActionListener will work well for a JCheckBox in a JTable since the check box isn’t a real button but rather a rendering of a checkbox. Perhaps playing with the table model will help. For instance you can use HTML to display a strike through of Strings displayed in table cells. For instance below I create a custom TableModel that extends DefaultTableModel and holds rows with a Boolean object followed by objects of a TextWrapper class that I’ve created that changes its toString result depending on a boolean.

    e.g.,

    import java.util.Vector;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    
    public class StrikeThroughRow {
       public static final Object[][] DATA = {{Boolean.TRUE, "Monday", "fe"},
          {Boolean.FALSE, "Tuesday", "fi"}, {Boolean.TRUE, "Wednesday", "fo"},
          {Boolean.FALSE, "Thursday", "fum"}, {Boolean.TRUE, "Friday", "foo"}};
    
       public StrikeThroughRow() {
    
       }
    
       private static void createAndShowUI() {
          JTable table = new JTable(new StrikeThroughModel(DATA));
          JScrollPane scrollpane = new JScrollPane(table);
    
          JFrame frame = new JFrame("StrikeThroughRow");
          frame.getContentPane().add(scrollpane);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    class StrikeThroughModel extends DefaultTableModel {
       public StrikeThroughModel(Object[][] data) {
          super(new String[]{"Check", "Work Day", "Giant Speak"}, 0);
          for (int i = 0; i < data.length; i++) {
             Vector<Object> rowVect = new Vector<Object>();
             rowVect.add(data[i][0]);
             if (data[i].length > 1) {
                for (int j = 1; j < data[i].length; j++) {
                   rowVect.add(new TextWrapper(data[i][j].toString(), (Boolean)data[i][0]));
                }
             }
             addRow(rowVect);
          }
       }
    
       @Override
       public Class<?> getColumnClass(int columnIndex) {
          if (columnIndex == 0) {
             return Boolean.class;
          }
          return super.getColumnClass(columnIndex);
       }
    
       @Override
       public void setValueAt(Object value, int row, int column) {
          if (column == 0) {
             for (int i = 1; i < getColumnCount(); i++) {
                TextWrapper textWrapper = (TextWrapper) getValueAt(row, i);
                textWrapper.setStrikeThrough((Boolean) value);
                fireTableCellUpdated(row, i);
             }
          }
          super.setValueAt(value, row, column);
       }
    }
    
    class TextWrapper {
       private String text;
       private boolean strikeThrough = false;
    
       public TextWrapper(String text) {
          this.text = text;
       }
    
       public TextWrapper(String text, boolean strikeThrough) {
          this(text);
          this.strikeThrough = strikeThrough;
       }
    
       @Override
       public String toString() {
          if (strikeThrough) {
             return "<html><strike>" + text + "</html></strike>"; 
          }
          return text;
       }
    
       public void setStrikeThrough(boolean strikeThrough) {
          this.strikeThrough = strikeThrough;
       }
    }
    

    I’m betting that there are better solutions including creating a custom renderer for your cells, but the code above offers a quick and dirty fix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable where the first column in each row is a checkbox.
I have a JTable . I want to know which row and column are
I have a JTable with 6 columns. The first column is a JCheckBox column.
I have a JTable and I need to remove a row, namely, the selected
I have a JTable that I want to use to display some data (a
I have a custom TableCellRenderer (ValueRenderer) for a JTable, the cell is a Checkbox
I have a JTable that is using a TableColumnModelListener() to detect when the column
I have a jTable as from the attached picture Right click on a row
I have a JTable with JLabel[][] as data. Now I want to detect a
I have Checkbox in JTable Header, I am using Nimbus L&F and customize the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.