I have a jtable where custom sorting is applied for data. When the table is launched initially , it has the columns with String data only so sorting goes fine. After table structure gets changed( new columns gets added which has a combination of Sting("N/A") and double data in same columns, the custom sorting algorithm seems to get removed. Now the columns with only string data still gets sorted because of defaultsorting with Jtable, but columns with mixed data gives classcastException. Is there I could keep the custom sorting or re-apply it as soon as tableStructureChange event occurs.
keeping the custom Sorting in jtable after table structure gets changed
1.3k Views Asked by Amit At
2
There are 2 best solutions below
0
camickr
On
The question is why is the tableStructureChanged event being generated? This implies the column structure of the table has changed, so how do you know the same columns will exist?
If you are doing a refresh of the table then why are you creating a whole new TableMode. Instead you can remove all the rows of data from the table (ie use setRowCount(0) in the DefaultTableModel) and then insert the new rows of data. This way the tableStructureEvent will not be generated.
The other option is to save the sorting information and recreate the sorter. You can get the current sort keys from the DefaultRowSorter. So the basic logic would be:
- getSortKeys()
- refresh TableModel
- recreate the sorter
- setSortKeys(...)
Check out: Trying to get the sorter positon to retain after a table refresh for a working example.
Related Questions in JAVA
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- Creating global Class holder
- No method found for class java.lang.String in Kafka
- Issue edit a jtable with a pictures
- getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
- Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
- Mixed color rendering in a JTable
- HTTPS configuration in Spring Boot, server returning timeout
- How to use Layout to create textfields which dont increase in size?
- Function for making the code wait in javafx
- How to create beans of the same class for multiple template parameters in Spring
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
- Postgres && statement Error in Mybatis Mapper?
Related Questions in SWING
- Issue edit a jtable with a pictures
- How to use Layout to create textfields which dont increase in size?
- How do I print a JTable in the form: Image + header + table in a single page (Java Swing)
- GUI window is not appearing
- Java program images not showing up
- Editing non-String values in JComboBox
- Use the same button in different interfaces (JAVA)
- Java Swing Paint Performance
- Frame showing up super small Java Swing
- Remove JTable cell truncation
- setBorderPainted, how to preserve effect on hover
- Subclassing from BasicButtonUI - text is rendered, but no border nor background
- Java paintComponent not display background image on JFrame
- Attempting to place JDIalog on top of current position of a JFrame
- 2 characters stop when other jump or 2 stop when changing the Direction - JAVA
Related Questions in SORTING
- Sorting a List by its property renames all the objects in the List
- Does Sort() method in C# use recursion?
- ARM Assembly code is not executing in Vitis IDE
- Creating an efficent and time-saving algorithm to find difference between greater than and lesser than combination
- Heap sort with multithreading
- Laravel Livewire data table sorting livewire update payload
- basic MergeSort exercise
- How to import a range into a variant array in Excel VBA and sort using the sort method?
- Looker Studio | pivot chart - sorting by metric and last month
- how to create an array of multiples of 5 and display it in reverse
- matplotlib sort barh by values
- Custom Sorting Javascript with A-Z set
- Mainframe Programming Sorting, OUTFIL REMOVECC,NODETAIL
- Soft list based on another list
- SQL query : creating table with distinct values on selected columns
Related Questions in JTABLE
- Issue edit a jtable with a pictures
- Mixed color rendering in a JTable
- How do I print a JTable in the form: Image + header + table in a single page (Java Swing)
- How to Override File Renaming Event Trigger in JList of JFileChooser
- Java JTable Checkbox in header
- Java CellEditor
- Java custom JTable handling multiple TableModels
- I want to be able to run main again after closing a JTable
- TableColumn.setHeaderRenderer vs. JTableHeader.setDefaultRenderer
- Why does adding an indeterminate JProgressBar to JTable kill the animation?
- java JTable select after sort
- difference between JTable.getColumnModel().getColumnCount() and model.getColumCount()
- Pacman positioning after resizing window Frame
- How to create summing row in JTable Java
- JTable not selectable in Windows Pro Builder
Related Questions in ROWSORTER
- Why does clicking on the header automatically sort the table?
- How to sort dates in a column in a JTable?
- BASH How to get minimum value from each row
- How to reset JTable column arrows
- Rowsorter JQuery Plugin issue
- JTable Keep Group of Rows always first when sorting ASC or DESC
- Issues when Search Filter and mouseClicked Event used in JTable
- Move down empty rows when using RowSorter.SortKey on JTable
- Sort a JTable with date in a column
- how to search two values using RowSorter JTable
- How to get the column of a sort key used by JTable's RowSorter?
- update jtable model after filtering
- How to get length of row from a rowsorted table?
- Sort other arrays by order of specific array?
- keeping the custom Sorting in jtable after table structure gets changed
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
this is how you should actually sort a Jtable. try with this code and post if theres any exceptions