Cách làm cho JScrollPane cuộn hai chiều (ngang và dọc) trong java swing

Như tiêu đề…có anh chị nào biết cho JScrollPane nó cuộn hai chiều ko…em đưa dữ liệu vào table mà nó chỉ cuộn theo chiều dọc thôi.còn chiều ngang thì bị khuất…ac bào biết chỉ em với.e cảm ơn

1 Like
JScrollBar createHorizontalScrollBar();

void setHorizontalScrollBar(JScrollBar horizontalScrollBar);

Mình thấy trong class JScrollPane thì có 2 method trên. Chưa làm thử nhưng mình nghĩ
bạn cần tạo 1 JScrollBar object http://docs.oracle.com/javase/7/docs/api/javax/swing/JScrollBar.html

Thêm vào JScrollBar sự kiện

void addAdjustmentListener(AdjustmentListener l)

rồi sau đó set cho JScrollPane.
Bạn làm thử xem được ko, đc thì post code lên mình tham khảo với.

1 Like

Mình thử rồi nhưng vẫn không được bạn ơi,help

Có cái ví dụ tham khảo:
http://www.cs.cf.ac.uk/Dave/HCI/HCI_Handout_CALLER/node63.html

Trong các constructor của JScrollPane có cái khởi tạo bằng 1 component:

public JScrollPane();

Creates an empty (no viewport view) JScrollPane
where both horizontal and vertical scrollbars appear when needed.

public JScrollPane(Component view);

Creates a JScrollPane that displays the contents of the specified
component, where both horizontal and vertical scrollbars appear
whenever the component’s contents are larger than the view.

2 Likes

Vẫn chưa fix được…chờ cao nhân xuất hiện…

đầu tiên kéo cái jscrollpane vào song kéo thêm pane vào đổi dữ liệu vào… khi nào tràn nó tự xuất hiện

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?