Scrollbar in JScrollPane does not work on JTables?

It's probably caused by the fact that that each table has its own JScrollPane (that's at least the case of your table C). When the mouse is inside a table, the inner-most scroll pane is the one that reacts to the mouse wheel. I don't think you should modify that: it's normal behaviour EDITED : It's ugly, but I'm not sure there is another way of doing it.

I've been able to make your example work by removing the listener added to the scroll pane by its UI (even if wheel scrolling is disabled) : for (MouseWheelListener listener : jScrollPane2. GetMouseWheelListeners()) { jScrollPane2. RemoveMouseWheelListener(listener); } // same for jScrollPane3 It's not elegant, but having a several scrollable tables inside a scrollabl panel isn't either.

It's probably caused by the fact that that each table has its own JScrollPane (that's at least the case of your table C). When the mouse is inside a table, the inner-most scroll pane is the one that reacts to the mouse wheel. I don't think you should modify that: it's normal behaviour.

EDITED : It's ugly, but I'm not sure there is another way of doing it. I've been able to make your example work by removing the listener added to the scroll pane by its UI (even if wheel scrolling is disabled) : for (MouseWheelListener listener : jScrollPane2. GetMouseWheelListeners()) { jScrollPane2.

RemoveMouseWheelListener(listener); } // same for jScrollPane3 It's not elegant, but having a several scrollable tables inside a scrollabl panel isn't either.

Well it's ok with 'C'. But when there are huge tables like A without scrollbars in them, it is annoying when jscrollpane's scroll stops unexpectedly. – Bhathiya Jun 26 at 15:22 Wow... you are great.

Thank you very much. :D – Bhathiya Jun 26 at 17:11.

I have a JScrollPane with number of huge JTables in it. I assume each of the child tables are also added to a JScrollPane. If so then the scroll event is being passed to these scroll panes and not the out scroll pane.So you need to use: scrollPane.

SetWheelScrollingEnabled( false ); on each of the scrollpanes contained within the main scrollpane. Update: The problem is that even though the scroll wheel has been disable, the scrollpane intercepts all the mouseScrolled events and they don't get passed to the parent scrollpane.So the solution is to not add the table to a scrollpane. Instead use a JPanel with a BorderLayout.

Something like: import java.awt. *; import java.util. *; import javax.swing.

*; import javax.swing.table. *; public class TableMultiple extends JPanel { public TableMultiple() { setLayout( new BorderLayout() ); Box box = Box. CreateVerticalBox(); box.

Add(Box. CreateVerticalStrut(50)); JPanel panel = new JPanel( new BorderLayout() ); JTable table = new JTable(10, 5); panel. Add(table.getTableHeader(), BorderLayout.

NORTH); panel. Add(table); box. Add( panel ); box.

Add(Box. CreateVerticalStrut(50)); JTable table2 = new JTable(100, 5); table2. SetPreferredScrollableViewportSize(table.

GetPreferredSize()); JScrollPane scrollPane2 = new JScrollPane( table2 ); box. Add( scrollPane2 ); box. Add(Box.

CreateVerticalStrut(50)); JTable table3 = new JTable(10, 5); box. Add( table3 ); box. Add(Box.

CreateVerticalStrut(50)); add( new JScrollPane(box) ); } private static void createAndShowUI() { JFrame frame = new JFrame("TableMultiple"); frame. SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame.

Add( new TableMultiple() ); frame. SetSize(400, 500); frame. SetLocationRelativeTo( null ); frame.

SetVisible( true ); } public static void main(String args) { EventQueue. InvokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } }.

Sorry, your answer is not clear to me. To be specific, I have only one jscrollpane and several jtables. – Bhathiya Jun 26 at 15:27 From the image "C" is a table contained in a scrollpane as well, so you have multiple scrollpanes.

That is why you are asked to post a SSCCE, because you can't even describe your problem correctly and we need the code to see what you are doing to make sure you don't make silly mistakes. – camickr Jun 26 at 15:31 I'm sorry now I get what you said. I disabled mouse scrolling of all the inner scrollpanes.(Now I can't scroll the table in C using mouse, it means the piece of code works) but the problem is still there.

:( – Bhathiya Jun 26 at 15:39 Right so now the user will need to drag the scrollbar or use the keyboard to scroll the inner scrollpanes. So its not a problem. Either the scrolling works on each child scroll pane or it works on the parent scroll pane, but it can't work on both at the same time.

You need to redefine your requirement because your original problem h as been solved. – camickr Jun 26 at 15:49 No the problem still exists regarding the table A. I tried removing scrollbars of inner scrollpanes too.

But no use. :( I added the full code of a simple program. – Bhathiya Jun 26 at 15:57.

I'd just do it using the Eclipse Visual Editor. The VE project has just died though. I like to code only the important Swing stuff, not every single JLabel...

To the maximum degree possible, work the same on all platforms. A GUI with JFC/Swing, a trail in The Java Tutorial. Generated from a user gesture.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions