1

i'm a student of science computing and I have a doubt ..

Is it possible to have 1 JScrollPane with 2 JTable inside? And, when I move the scroll, the table 1 and table 2 move together?

DanJhonatan
  • 15
  • 1
  • 4

2 Answers2

2

Is it possible to have 1 JScrollPane with 2 JTable inside?

  • not good idea, because JScrollPane is designated to nest only one JComponent, any attempts have got issue with natural scrolling

  • and JTable in is designated has inside the JScrollPane

And, when I move the scroll, the table 1 and table 2 move together?

  • yes is simple and possible, to create two JTables with JScrollPanes, then to use AdjustmentListener added to JScrollBar(s), derived directly from both JScrollPane, example for AdjustmentListener
Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 1
    Also consider hiding one scroll bar and sharing models, seen [here](http://stackoverflow.com/q/2614457/230513). – trashgod Aug 20 '15 at 16:40
  • mKorbel, Thank you. It is exactely what I was looking for. trashgod, thank you too. you improved my GUI. – DanJhonatan Nov 27 '15 at 12:47
0

Add both JTable instances to a JPanel with BorderLayout, using NORTH and SOUTH constraints, and then add the JPanel to JScrollPane.

Toilal
  • 3,301
  • 1
  • 24
  • 32