JTable이 표시되는지 확인할 수있는 방법은 무엇입니까?
출처 : Determines if the component is visible in its window at the given screen location.
import java.awt.Component;
import java.awt.Point;
import java.awt.Window;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
/**
* This class contains a collection of static utility methods for Swing.
*
* @author Heidi Rakels.
*/
public class SwingUtil
{
/**
* <p>
* Determines if the component is visible in its window at the given screen location.
* </p>
*
* @param location A location on the screen.
* @param component A component in a window.
* @return True if the component is visible in its window at the given screen location.
*/
public static boolean locationInComponentVisible(Point location, Component component)
{
// Get the root component in the window.
JRootPane rootPane = getRootPane(component);
if (rootPane != null)
{
Component rootComponent = rootPane.getContentPane();
if (rootComponent != null)
{
// Get the location relative to this root component.
Point locationInRoot = new Point(location);
SwingUtilities.convertPointFromScreen(locationInRoot, rootComponent);
// Get the deepest visible component at the given location.
Component deepestComponent = SwingUtilities.getDeepestComponentAt(rootComponent, locationInRoot.x, locationInRoot.y);
if (deepestComponent != null)
{
boolean result = SwingUtilities.isDescendingFrom(deepestComponent, component);
return result;
}
}
}
return false;
}
/**
* Gets the root pane of the given component.
*
* @param component The component whose root pane is retrieved.
* @return The root pane of the component.
*/
public static JRootPane getRootPane(Component component)
{
if (component instanceof JRootPane) {
return (JRootPane)component;
}
if (component.getParent() != null) {
return getRootPane(component.getParent());
}
// Get the window of the component.
Window window = SwingUtilities.windowForComponent(component);
return getRootPane(window);
}
}
그것은 꽤 곧장 앞으로 질문입니다. 그러나 동시에, 머리 꼭대기에서 대답이 알려지지 않은 (나 자신과 같은) 사람들은 테스트하고 싶다. [간단한 실행 가능한 예제]를 가지고 있으면 좋을 것이다. (http : // stackoverflow .com/help/mcve), 우리는 스스로를 쓸 필요가 없다. 일부는 너무 게으 르어 서 하나를 쓰는 것을 고려하면 더 많은 잠재 고객을 확보하게됩니다. 그냥 FYI –
@peeskillet : 네, 멋진, 질문을 업데이 트됩니다. –
그냥 호기심 -이 문맥에서, 'JTable'이 보이게되고, 테이블이있는 탭과 동일합니까? –