How to keep items in jtable and jlist visible

Source: Internet
Author: User
View the jdk api documentation. We know that jtable has two functions: setcolumnselectioninterval (INT beginindex, int endindex), which can be used to select the specified column; setrowselectioninterval (INT beginindex, int endindex), you can select the specified row. When the jtable contains many columns or rows, it is okay to call these two functions. However, this may occur when the specified row or column has been selected, the row or column is not in the visible area. You need to drag the scroll bar to view the selected row or column. In this way, the user experience is not very good.
The most direct idea is to see if jtable provides APIs for calling. For jtree, the following functions are available: scrollpathtovisible (treepath path) and scrollrowtovisible (INT row ). Call one of the functions to achieve the goal. Jtable does not provide such a function. Jcomponent provides the scrollrecttovisible (rectangle rect) function ). Through this function, you can still implement jtable scrolling. The scrollrecttovisible function forwards the call to its parent container for processing. The parent container chooses to continue forwarding or process the request.
The scrollrecttovisible function receives only one rectangle parameter, indicating which region you want to be visible. For jtable, obtain the required parameters in the following way:
Int x = jtable1.getbounds (). X;
Int y = jtable1.getrowheight () * rowindex;
Int width = jtable1.getbounds (). width;
Int Height = jtable1.getrowheight ();
Jtable1.scrollrecttovisible (New rectangle (X, Y, width, height ));

Jlist can be implemented as follows:
Jlist1.scrollrecttovisible (jlist1.getcellbounds (rowindex, rowindex ));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.