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 8338337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:33:45+00:00 2026-06-09T04:33:45+00:00

So I have successfully implemented a search feature into my tiny program but when

  • 0

So I have successfully implemented a search feature into my tiny program but when I click the button to sort, it works fine but the images don’t display. This is the code that I added for the sorter which works fine but the images for each row don’t show up. When I take out this code, the images show up but the sorting doesn’t work. Is there away that I can make the images show when sorting?

    // Sorter Code. Images show up when this code gets taken out.
    table = new JTable(model);
    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);
    search_button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          String text = search.getText();
          if (text.length() == 0) {
            sorter.setRowFilter(null);
          } else {
            sorter.setRowFilter(RowFilter.regexFilter(text));
          }
        }
      });
   // sorter code ends here.
  • 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-06-09T04:33:46+00:00Added an answer on June 9, 2026 at 4:33 am
    • have to synchronize JTables view with its model,

    • have look at methods convertXxxIndexToXxx

    • add int modelRow = convertRowIndexToModel(row); to your Renderer or prepareRenderer

    • example convertRowIndexToModel

    EDIT

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.util.regex.PatternSyntaxException;
    import javax.swing.*;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import javax.swing.table.*;
    
    public class TableIcon extends JFrame implements Runnable {
    
        private static final long serialVersionUID = 1L;
        private JTable table;
        private JLabel myLabel = new JLabel("waiting");
        private int pHeight = 40;
        private boolean runProcess = true;
        private int count = 0;
        private JTextField filterText = new JTextField(15);
    
        public TableIcon() {
            ImageIcon errorIcon = (ImageIcon) UIManager.getIcon("OptionPane.errorIcon");
            ImageIcon infoIcon = (ImageIcon) UIManager.getIcon("OptionPane.informationIcon");
            ImageIcon warnIcon = (ImageIcon) UIManager.getIcon("OptionPane.warningIcon");
            String[] columnNames = {"Picture", "Description"};
            Object[][] data = {{errorIcon, "About"}, {infoIcon, "Add"}, {warnIcon, "Copy"},};
            DefaultTableModel model = new DefaultTableModel(data, columnNames) {
    
                private static final long serialVersionUID = 1L;
                //  Returning the Class of each column will allow different
                //  renderers to be used based on Class
    
                @Override
                public Class getColumnClass(int column) {
                    return getValueAt(0, column).getClass();
                }
            };
            table = new JTable(model);
            table.setRowHeight(pHeight);
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
            table.setRowSorter(sorter);
            filterText.setMaximumSize(new Dimension(400, 30));
            filterText.setFont(new Font("Serif", Font.BOLD, 20));
            filterText.setForeground(Color.BLUE);
            filterText.getDocument().addDocumentListener(new DocumentListener() {
    
                private void searchFieldChangedUpdate(DocumentEvent evt) {
                    String text = filterText.getText();
                    if (text.length() == 0) {
                        sorter.setRowFilter(null);
                        table.clearSelection();
                    } else {
                        try {
                            sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
                        } catch (PatternSyntaxException pse) {
                            JOptionPane.showMessageDialog(null, "Bad regex pattern", "Bad regex pattern", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
    
                @Override
                public void insertUpdate(DocumentEvent evt) {
                    searchFieldChangedUpdate(evt);
                }
    
                @Override
                public void removeUpdate(DocumentEvent evt) {
                    searchFieldChangedUpdate(evt);
                }
    
                @Override
                public void changedUpdate(DocumentEvent evt) {
                    searchFieldChangedUpdate(evt);
                }
            });
            add(filterText, BorderLayout.NORTH);
            JScrollPane scrollPane = new JScrollPane(table);
            add(scrollPane, BorderLayout.CENTER);
            myLabel.setPreferredSize(new Dimension(200, pHeight));
            myLabel.setHorizontalAlignment(SwingConstants.CENTER);
            add(myLabel, BorderLayout.SOUTH);
            new Thread(this).start();
        }
    
        public void run() {
            while (runProcess) {
                try {
                    Thread.sleep(1250);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                SwingUtilities.invokeLater(new Runnable() {
    
                    @Override
                    public void run() {
                        ImageIcon myIcon = (ImageIcon) table.getModel().getValueAt(count, 0);
                        String lbl = "JTable Row at :  " + count;
                        myLabel.setIcon(myIcon);
                        myLabel.setText(lbl);
                        count++;
                        if (count > 2) {
                            count = 0;
                        }
                    }
                });
            }
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    TableIcon frame = new TableIcon();
                    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
                    frame.setLocation(150, 150);
                    frame.pack();
                    frame.setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully implemented django-ajax-uploader into my project. But I do not know how
I have successfully implemented iAd into my App just this past week, but when
I have successfully implemented a cel shader using glsl. But my problem is about
I have successfully implemented a network application in visual CLR project using boost.asio. but
I have successfully implemented my GridView now, but, as always, the whole ASP.NET life
I have implemented search for my customers master successfully, and it searches the entire
I have successfully implemented Autocomplete field from database using sfWidgetFormJQueryAutocompleter but i cannot a
I have successfully implemented embedded vimeo videos into my app, however i would like
I have successfully implemented the mandelbrot set as described in the wikipedia article, but
I have successfully implemented a restful service that works with my own client. Now,

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.