Search code examples
javaswingjtablejtextfieldjtabbedpane

Java swing - one searchbox for multiple tabs


I want to have a GUI application which would contain multiple tabs, each with its own Table. I would like to include a search box below the tabs which would filter the currently selected tab. How can this dynamic behaviour be achieved?


Solution

    1. figure one you can to share RowSorter/RowFilter for all JTables in current JVM instance

      • filtering works for all JTables

      • notice there could be performance issue in the case that there is/are JTable(s) contains bunch of rows

      • quite possible for JTables that contains a few (limited number of) rows together

    2. determine (from arrays of tabs) visible tab, visible JComponents(or have to look at SwingUtilities), then remove RowSorter/RowFilter from all JTables instances and then to add RowSorter/RowFilter to the visible an focusable JTable

    3. JTextField for RowSorter/RowFilter should be crated only once times