下面列出了怎么用javax.swing.plaf.TabbedPaneUI的API类实例代码及写法,或者点击链接到github查看源代码。
private void maybeShowKeyStoreTabPopup(MouseEvent evt) {
if (evt.isPopupTrigger()) {
int tabCount = jkstpKeyStores.getTabCount();
TabbedPaneUI tpu = jkstpKeyStores.getUI();
for (int i = 0; i < tabCount; i++) {
Rectangle rect = tpu.getTabBounds(jkstpKeyStores, i);
int x = evt.getX();
int y = evt.getY();
if (x < rect.x || x > rect.x + rect.width || y < rect.y || y > rect.y + rect.height) {
continue;
}
jpmKeyStoreTab.show(evt.getComponent(), evt.getX(), evt.getY());
break;
}
}
}
private void handlePopup( final MouseEvent e ) {
final JTabbedPane reportEditorPane = getReportEditorPane();
final TabbedPaneUI ui = reportEditorPane.getUI();
final int tabIndex = ui.tabForCoordinate( reportEditorPane, e.getX(), e.getY() );
final JPopupMenu popupMenu = new JPopupMenu();
final CloseReportAction closeThisAction = new CloseReportAction( tabIndex );
closeThisAction.setReportDesignerContext( getContext() );
final CloseChildReportsAction closeChildsAction = new CloseChildReportsAction( tabIndex );
closeChildsAction.setReportDesignerContext( getContext() );
final CloseOtherReportsAction closeOthersAction = new CloseOtherReportsAction( tabIndex );
closeOthersAction.setReportDesignerContext( getContext() );
final CloseAllReportsAction closeAllAction = new CloseAllReportsAction();
closeAllAction.setReportDesignerContext( getContext() );
final CloseUnmodifiedReportsAction closeUnmodifiedReportsAction = new CloseUnmodifiedReportsAction();
closeUnmodifiedReportsAction.setReportDesignerContext( getContext() );
popupMenu.add( new JMenuItem( closeThisAction ) );
popupMenu.addSeparator();
popupMenu.add( new JMenuItem( closeChildsAction ) );
popupMenu.add( new JMenuItem( closeUnmodifiedReportsAction ) );
popupMenu.add( new JMenuItem( closeOthersAction ) );
popupMenu.add( new JMenuItem( closeAllAction ) );
popupMenu.show( reportEditorPane, e.getX(), e.getY() );
}
/**
* Moves {@link JTabbedPane} scrollable tabs view according to scroll amount.
*
* @param tabbedPane {@link JTabbedPane}
* @param scrollAmount either positive or negative blocks scroll amount
*/
protected void scroll ( final T tabbedPane, final int scrollAmount )
{
final TabbedPaneUI ui = tabbedPane.getUI ();
if ( ui instanceof WTabbedPaneUI )
{
final TabContainer tabContainer = ( ( WTabbedPaneUI ) ui ).getTabContainer ();
if ( tabContainer != null )
{
final boolean horizontal = tabbedPane.getTabPlacement () == JTabbedPane.TOP ||
tabbedPane.getTabPlacement () == JTabbedPane.BOTTOM;
final Rectangle vr = tabContainer.getVisibleRect ();
final Rectangle bounds = new Rectangle ( tabContainer.getSize () );
if ( horizontal )
{
vr.x += scrollAmount * vr.width;
}
else
{
vr.y += scrollAmount * vr.height;
}
tabContainer.scrollRectToVisible ( bounds.intersection ( vr ) );
}
}
}
private DarkTabbedPaneUI supportsIndicator(final Component c) {
if (c instanceof JTabbedPane) {
TabbedPaneUI ui = ((JTabbedPane) c).getUI();
if (ui instanceof DarkTabbedPaneUI) {
return ((DarkTabbedPaneUI) ui);
}
}
return null;
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getTabBounds</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle getTabBounds(JTabbedPane a, int b) {
Rectangle returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabBounds(a,b);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabBounds(a,b);
}
return returnValue;
}
/**
* Invokes the <code>getTabRunCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getTabRunCount(JTabbedPane a) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabRunCount(a);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabRunCount(a);
}
return returnValue;
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getTabBounds</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle getTabBounds(JTabbedPane a, int b) {
Rectangle returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabBounds(a,b);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabBounds(a,b);
}
return returnValue;
}
/**
* Invokes the <code>getTabRunCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getTabRunCount(JTabbedPane a) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabRunCount(a);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabRunCount(a);
}
return returnValue;
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getTabBounds</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle getTabBounds(JTabbedPane a, int b) {
Rectangle returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabBounds(a,b);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabBounds(a,b);
}
return returnValue;
}
/**
* Invokes the <code>getTabRunCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getTabRunCount(JTabbedPane a) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabRunCount(a);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabRunCount(a);
}
return returnValue;
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getTabBounds</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle getTabBounds(JTabbedPane a, int b) {
Rectangle returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabBounds(a,b);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabBounds(a,b);
}
return returnValue;
}
/**
* Invokes the <code>getTabRunCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getTabRunCount(JTabbedPane a) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabRunCount(a);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabRunCount(a);
}
return returnValue;
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getTabBounds</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle getTabBounds(JTabbedPane a, int b) {
Rectangle returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabBounds(a,b);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabBounds(a,b);
}
return returnValue;
}
/**
* Invokes the <code>getTabRunCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getTabRunCount(JTabbedPane a) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabRunCount(a);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabRunCount(a);
}
return returnValue;
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getTabBounds</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle getTabBounds(JTabbedPane a, int b) {
Rectangle returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabBounds(a,b);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabBounds(a,b);
}
return returnValue;
}
/**
* Invokes the <code>getTabRunCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getTabRunCount(JTabbedPane a) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabRunCount(a);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabRunCount(a);
}
return returnValue;
}
/** Called when the seqeunce of mouse events should lead to actual
* showing of the popup menu. */
@Override
protected void showPopup(java.awt.event.MouseEvent mouseEvent) {
TabbedPaneUI tabUI = mergeTabbedPane.getUI();
int clickTab = tabUI.tabForCoordinate(mergeTabbedPane, mouseEvent.getX(), mouseEvent.getY());
MergePanel panel = getSelectedMergePanel();
if (panel == null) {
return;
}
if (clickTab != -1) {
//Click is on valid tab, not on empty area in tab
showPopupMenu(createPopupMenu(panel), mouseEvent.getPoint(), mergeTabbedPane);
}
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getTabBounds</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle getTabBounds(JTabbedPane a, int b) {
Rectangle returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabBounds(a,b);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabBounds(a,b);
}
return returnValue;
}
/**
* Invokes the <code>getTabRunCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getTabRunCount(JTabbedPane a) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).getTabRunCount(a);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).getTabRunCount(a);
}
return returnValue;
}
/**
* Sets the UI object which implements the L&F for this component.
*
* @param ui the new UI object
* @see UIDefaults#getUI
*/
@BeanProperty(hidden = true, visualUpdate = true, description
= "The UI object that implements the tabbedpane's LookAndFeel")
public void setUI(TabbedPaneUI ui) {
super.setUI(ui);
// disabled icons are generated by LF so they should be unset here
for (int i = 0; i < getTabCount(); i++) {
Icon icon = pages.get(i).disabledIcon;
if (icon instanceof UIResource) {
setDisabledIconAt(i, null);
}
}
}
/**
* Returns the tooltip text for the component determined by the
* mouse event location.
*
* @param event the <code>MouseEvent</code> that tells where the
* cursor is lingering
* @return the <code>String</code> containing the tooltip text
*/
public String getToolTipText(MouseEvent event) {
if (ui != null) {
int index = ((TabbedPaneUI)ui).tabForCoordinate(this, event.getX(), event.getY());
if (index != -1) {
return pages.get(index).tip;
}
}
return super.getToolTipText(event);
}
/**
* Returns the <code>Accessible</code> child contained at
* the local coordinate <code>Point</code>, if one exists.
* Otherwise returns the currently selected tab.
*
* @return the <code>Accessible</code> at the specified
* location, if it exists
*/
public Accessible getAccessibleAt(Point p) {
int tab = ((TabbedPaneUI) ui).tabForCoordinate(JTabbedPane.this,
p.x, p.y);
if (tab == -1) {
tab = getSelectedIndex();
}
return getAccessibleChild(tab);
}
/**
* Invokes the <code>tabForCoordinate</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int tabForCoordinate(JTabbedPane a, int b, int c) {
int returnValue =
((TabbedPaneUI) (uis.elementAt(0))).tabForCoordinate(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TabbedPaneUI) (uis.elementAt(i))).tabForCoordinate(a,b,c);
}
return returnValue;
}