StyledText 可见行数

aph*_*hex 0 java swt

我想知道 StyledText 实际显示了多少行。有可能吗?

谢谢。

Fre*_*red 5

试试这个代码:

// The index of the last (possibly only partially) visible line of the widget
int bottomIndex = JFaceTextUtil.getPartialBottomIndex((StyledText)widget);
// The index of the first (possibly only partially) visible line of the widget
int topIndex = JFaceTextUtil.getPartialTopIndex((StyledText)widget);


int visibleLines = bottomIndex - topIndex;
Run Code Online (Sandbox Code Playgroud)