下面列出了javax.swing.JTabbedPane#TOP 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* The index at which a tab should be inserted if a drop operation occurs at
* this point.
*
* @param location A point anywhere on the TabbedContainer
* @return A tab index, or -1
*/
public int dropIndexOfPoint( Point location ) {
int index = indexAtLocation( location.x, location.y );
if( index < 0 ) {
index = getTabCount();
} else if( index == getTabCount()-1 ) {
Rectangle rect = getBoundsAt( index );
if( getTabPlacement() == JTabbedPane.TOP || getTabPlacement() == JTabbedPane.BOTTOM ) {
if( location.x > rect.x + rect.width/2 )
index++;
} else {
if( location.y > rect.y + rect.height/2 )
index++;
}
}
return index;
}
/**
* Defines the tab placement. The possible bundle values are <code>top</code>, <code>bottom</code>, <code>left</code>, <code>right</code>.
* @return Tab placement when JTabbedPane implementation of Tab Control is
* being used. The return value is one of <code>JTabbedPane.TOP</code> (default), <code>JTabbedPane.BOTTOM</code>,
* <code>JTabbedPane.LEFT</code>, <code>JTabbedPane.RIGHT</code>.
*
* @see JTabbedPane#getTabPlacement()
*
* @since 2.44
*/
public static int getSimpleTabsPlacement() {
int result = JTabbedPane.TOP;
try {
String resValue = NbBundle.getMessage(Switches.class, "WinSys.TabControl.SimpleTabs.Placement" ); //NOI18N
if( "bottom".equals( resValue ) )
result = JTabbedPane.BOTTOM;
else if( "right".equals( resValue ) )
result = JTabbedPane.RIGHT;
else if( "left".equals( resValue ) )
result = JTabbedPane.LEFT;
} catch( MissingResourceException mrE ) {
//ignore
}
return result;
}
private Rectangle offsetRect() {
Rectangle rect = new Rectangle();
if (UIUtils.isNimbus()) {
rect.height = 4;
if (getTabPlacement() == JTabbedPane.TOP) rect.y -= rect.height;
} else if (UIUtils.isGTKLookAndFeel()) {
rect.height = 1;
if (getTabPlacement() == JTabbedPane.TOP) rect.y -= rect.height++;
} else {
Insets tai = UIManager.getInsets("TabbedPane.tabAreaInsets"); // NOI18N
Insets cbi = UIManager.getInsets("TabbedPane.contentBorderInsets"); // NOI18N
if (tai != null && cbi != null) {
if (getTabPlacement() == JTabbedPane.TOP) {
rect.y -= cbi.bottom;
rect.height -= rect.y;
} else {
rect.height = tai.bottom + cbi.bottom - 1;
}
} else {
}
}
return rect;
}
@Override
public void run() {
JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
pane.addTab("first", new JButton("first"));
pane.addTab("second", new JButton("second"));
for (Component component : pane.getComponents()) {
component.setSize(100, 100);
}
}
@Override
public void run() {
JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
pane.addTab("first", new JButton("first"));
pane.addTab("second", new JButton("second"));
for (Component component : pane.getComponents()) {
component.setSize(100, 100);
}
}
public IMContactView(IMPanel imPanel) {
this.imPanel = imPanel;
setLayout(new BorderLayout(0, 0));
tabHost = new JTabbedPane(JTabbedPane.TOP);
add(tabHost, BorderLayout.CENTER);
// JScrollPane scrollPane = new JScrollPane();
// tabHost.addTab("New tab", null, scrollPane, null);
}
/**
* Create the dialog.
*/
public BroadcastDialog(IMPanel imPanel) {
this.imPanel = imPanel;
setLocationRelativeTo(null);
setSize(400, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(new BorderLayout(0, 0));
{
text = new JTextArea();
text.setRows(4);
text.setLineWrap(true);
JScrollPane scrollPane = new JScrollPane(text);
contentPanel.add(scrollPane, BorderLayout.NORTH);
}
{
tabHost = new JTabbedPane(JTabbedPane.TOP);
contentPanel.add(tabHost, BorderLayout.CENTER);
}
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
okButton.addActionListener(this);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
cancelButton.addActionListener(this);
}
}
initTab(tabHost);
}
@Override
public void run() {
JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
pane.addTab("first", new JButton("first"));
pane.addTab("second", new JButton("second"));
for (Component component : pane.getComponents()) {
component.setSize(100, 100);
}
}
public boolean isEnabled() {
boolean res = false;
ProjectSupport projectSupport = ProjectSupport.getDefault();
res |= isShowFolderName();
res |= isSameProjectSameColor() && projectSupport.isEnabled();
res |= isShowFullPath();
res |= isSortDocumentListByProject() && projectSupport.isEnabled();
res |= getRowCount() > 1;
res |= isTabRowPerProject() && projectSupport.isEnabled();
res |= getTabsLocation() != JTabbedPane.TOP;
return res;
}
private void fireChanged() {
boolean isChanged = false;
if (checkShowFolderName.isSelected() != settings.isShowFolderName()
|| checkShowFullPath.isSelected() != settings.isShowFullPath()
|| checkProjectColors.isSelected() != settings.isSameProjectSameColor()
|| checkSortDocumentList.isSelected() != settings.isSortDocumentListByProject()) {
isChanged = true;
}
int rowCount = settings.getRowCount();
if (checkMultiRow.isSelected() && radioRowCount.isSelected()) {
rowCount = ((Number) spinRowCount.getValue()).intValue();
}
if (checkMultiRow.isSelected() != (rowCount > 1 || settings.isTabRowPerProject())) {
isChanged = true;
}
if (rowCount != settings.getRowCount()) {
isChanged = true;
}
if (radioRowPerProject.isSelected() != settings.isTabRowPerProject()) {
isChanged = true;
}
if(radioPlacementBottom.isSelected() && settings.getTabsLocation() != JTabbedPane.BOTTOM
|| radioPlacementLeft.isSelected() && settings.getTabsLocation() != JTabbedPane.LEFT
|| radioPlacementRight.isSelected() && settings.getTabsLocation() != JTabbedPane.RIGHT
|| radioPlacementTop.isSelected() && settings.getTabsLocation() != JTabbedPane.TOP) {
isChanged = true;
}
controller.changed(null, isChanged);
}
@Override
public void run() {
JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
pane.addTab("first", new JButton("first"));
pane.addTab("second", new JButton("second"));
for (Component component : pane.getComponents()) {
component.setSize(100, 100);
}
}
@Override
public void run() {
JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
pane.addTab("first", new JButton("first"));
pane.addTab("second", new JButton("second"));
for (Component component : pane.getComponents()) {
component.setSize(100, 100);
}
}
/**
* Launch SwingAppleCommander.
*/
public void launch() {
JMenuBar menuBar = createMenuBar();
JToolBar toolBar = new JToolBar();
JPanel topPanel = new JPanel(new BorderLayout());
tabPane = new JTabbedPane(JTabbedPane.TOP);
topPanel.add(menuBar,BorderLayout.NORTH);
topPanel.add(toolBar,BorderLayout.SOUTH);
JButton aButton = new JButton(textBundle.get("OpenButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/opendisk.gif")))); //$NON-NLS-1$
aButton.setToolTipText(textBundle.get("SwtAppleCommander.OpenDiskImageTooltip")); //$NON-NLS-1$
aButton.setHorizontalTextPosition(JLabel.CENTER);
aButton.setVerticalTextPosition(JLabel.BOTTOM);
aButton.addActionListener(this);
toolBar.add(aButton);
JButton aButton2 = new JButton(textBundle.get("CreateButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/newdisk.gif")))); //$NON-NLS-1$
aButton2.setToolTipText(textBundle.get("SwtAppleCommander.CreateDiskImageTooltip")); //$NON-NLS-1$
aButton2.setHorizontalTextPosition(JLabel.CENTER);
aButton2.setVerticalTextPosition(JLabel.BOTTOM);
aButton2.addActionListener(this);
toolBar.add(aButton2);
JButton aButton3 = new JButton(textBundle.get("CompareButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/comparedisks.gif")))); //$NON-NLS-1$
aButton3.setToolTipText(textBundle.get("SwtAppleCommander.CompareDiskImageTooltip")); //$NON-NLS-1$
aButton3.setHorizontalTextPosition(JLabel.CENTER);
aButton3.setVerticalTextPosition(JLabel.BOTTOM);
aButton3.addActionListener(this);
toolBar.add(aButton3);
JButton aButton4 = new JButton(textBundle.get("AboutButton"), new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/about.gif")))); //$NON-NLS-1$
aButton4.setToolTipText(textBundle.get("SwtAppleCommander.AboutTooltip")); //$NON-NLS-1$
aButton4.setHorizontalTextPosition(JLabel.CENTER);
aButton4.setVerticalTextPosition(JLabel.BOTTOM);
aButton4.addActionListener(this);
toolBar.add(aButton4);
SwingAppleCommander application = new SwingAppleCommander();
application.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/diskicon.gif"))); //$NON-NLS-1$
application.setTitle(textBundle.get("SwtAppleCommander.AppleCommander"));
titleLabel = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/webcodepro/applecommander/ui/images/AppleCommanderLogo.jpg"))));
addTitleTabPane();
application.getContentPane().add(topPanel, BorderLayout.NORTH);
application.getContentPane().add(tabPane, BorderLayout.CENTER);
application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
application.pack();
application.setVisible(true);
}
public static void main(String[] args) {
LibraryConfiguration.parallel = false;
LibraryConfiguration.quiet = false;
LibraryConfiguration.emit_block_debug = true;
tabs.put(TabType.SOURCE, new TabData(TabType.SOURCE));
tabs.put(TabType.BYTECODE, new TabData(TabType.BYTECODE));
tabs.put(TabType.DECOMPILED, new TabData(TabType.DECOMPILED));
tabs.put(TabType.GRAPH_0, new TabData(TabType.GRAPH_0));
tabs.put(TabType.GRAPH_1, new TabData(TabType.GRAPH_1));
tabs.put(TabType.GRAPH_2, new TabData(TabType.GRAPH_2));
JFrame frame = new JFrame("Despector");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(50, 50, 1600, 900);
JPanel contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
frame.setContentPane(contentPane);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.NORTH);
file_name_field = new JTextField();
panel.add(file_name_field);
file_name_field.setColumns(100);
file_name_field.setText("net.minecraft.");
JButton loadBtn = new JButton("Load");
panel.add(loadBtn);
loadBtn.addActionListener(Viewer::onLoad);
JSplitPane splitPane = new JSplitPane();
splitPane.setDividerLocation(800);
contentPane.add(splitPane, BorderLayout.CENTER);
JTabbedPane leftPane = new JTabbedPane(JTabbedPane.TOP);
splitPane.setLeftComponent(leftPane);
leftPane.addTab("Source", null, new JScrollPane(tabs.get(TabType.SOURCE).left), null);
leftPane.addTab("Bytecode", null, new JScrollPane(tabs.get(TabType.BYTECODE).left), null);
leftPane.addTab("Decompiled", null, new JScrollPane(tabs.get(TabType.DECOMPILED).left), null);
leftPane.addTab("Graph 0", null, new JScrollPane(tabs.get(TabType.GRAPH_0).left), null);
leftPane.addTab("Graph 1", null, new JScrollPane(tabs.get(TabType.GRAPH_1).left), null);
leftPane.addTab("Graph 2", null, new JScrollPane(tabs.get(TabType.GRAPH_2).left), null);
JTabbedPane rightPane = new JTabbedPane(JTabbedPane.TOP);
splitPane.setRightComponent(rightPane);
rightPane.addTab("Source", null, new JScrollPane(tabs.get(TabType.SOURCE).right), null);
rightPane.addTab("Bytecode", null, new JScrollPane(tabs.get(TabType.BYTECODE).right), null);
rightPane.addTab("Decompiled", null, new JScrollPane(tabs.get(TabType.DECOMPILED).right), null);
rightPane.addTab("Graph 0", null, new JScrollPane(tabs.get(TabType.GRAPH_0).right), null);
rightPane.addTab("Graph 1", null, new JScrollPane(tabs.get(TabType.GRAPH_1).right), null);
rightPane.addTab("Graph 2", null, new JScrollPane(tabs.get(TabType.GRAPH_2).right), null);
frame.setVisible(true);
}
private void initComponents() {
urlField = new JComboBox<>();
urlField.setEditable(true);
urlField.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
refreshButton.doClick();
}
}
});
updateUrlField();
refreshButton = ToolButtonFactory.createButton(
TangoIcons.actions_view_refresh(TangoIcons.Res.R22),
false);
refreshButton.addActionListener(e -> {
final boolean usingUrl = refresh();
if (usingUrl) {
final String urls = preferences.get(PROPERTY_KEY_SERVER_URLS, "");
final String currentUrl = urlField.getSelectedItem().toString();
if (!urls.contains(currentUrl)) {
preferences.put(PROPERTY_KEY_SERVER_URLS, urls + "\n" + currentUrl);
updateUrlField();
}
}
});
metaInfoArea = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
JTextArea ddsArea = new JTextArea(10, 40);
JTextArea dasArea = new JTextArea(10, 40);
ddsArea.setEditable(false);
dasArea.setEditable(false);
textAreas = new HashMap<>();
textAreas.put(DAS_AREA_INDEX, dasArea);
textAreas.put(DDS_AREA_INDEX, ddsArea);
metaInfoArea.addTab("DDS", new JScrollPane(ddsArea));
metaInfoArea.addTab("DAS", new JScrollPane(dasArea));
metaInfoArea.setToolTipTextAt(DDS_AREA_INDEX, "Dataset Descriptor Structure: description of dataset variables");
metaInfoArea.setToolTipTextAt(DAS_AREA_INDEX, "Dataset Attribute Structure: description of dataset attributes");
metaInfoArea.addChangeListener(e -> {
if (catalogTree.getSelectedLeaf() != null) {
setMetadataText(metaInfoArea.getSelectedIndex(), catalogTree.getSelectedLeaf());
}
});
catalogTree = new CatalogTree(new DefaultLeafSelectionListener(), appContext, this);
useDatasetNameFilter = new JCheckBox("Use dataset name filter");
useTimeRangeFilter = new JCheckBox("Use time range filter");
useRegionFilter = new JCheckBox("Use region filter");
useVariableFilter = new JCheckBox("Use variable name filter");
DefaultFilterChangeListener filterChangeListener = new DefaultFilterChangeListener();
datasetNameFilter = new DatasetNameFilter(useDatasetNameFilter);
datasetNameFilter.addFilterChangeListener(filterChangeListener);
timeRangeFilter = new TimeRangeFilter(useTimeRangeFilter);
timeRangeFilter.addFilterChangeListener(filterChangeListener);
regionFilter = new RegionFilter(useRegionFilter);
regionFilter.addFilterChangeListener(filterChangeListener);
variableFilter = new VariableFilter(useVariableFilter, catalogTree);
variableFilter.addFilterChangeListener(filterChangeListener);
catalogTree.addCatalogTreeListener(new CatalogTree.CatalogTreeListener() {
@Override
public void leafAdded(OpendapLeaf leaf, boolean hasNestedDatasets) {
if (hasNestedDatasets) {
return;
}
if (leaf.getDataset().getGeospatialCoverage() != null) {
useRegionFilter.setEnabled(true);
}
filterLeaf(leaf);
}
@Override
public void catalogElementsInsertionFinished() {
}
});
openInVisat = new JCheckBox("Open in SNAP");
statusBarMessage = new JLabel("Ready.");
statusBarMessage.setText("Ready.");
preMessageLabel = new JLabel();
postMessageLabel = new JLabel();
progressBar = new JProgressBar(0, 100);
statusBar = new JPanel();
statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.X_AXIS));
statusBar.add(statusBarMessage);
statusBar.add(Box.createHorizontalStrut(4));
statusBar.add(preMessageLabel);
statusBar.add(Box.createHorizontalGlue());
statusBar.add(progressBar);
statusBar.add(Box.createHorizontalGlue());
statusBar.add(postMessageLabel);
useRegionFilter.setEnabled(false);
}
public AbstractTabDisplayer( final TabDataModel tabModel, int tabsLocation ) {
super( tabModel );
setLayout( new BorderLayout( 3, 3 ) );
this.orientation = tabsLocation == JTabbedPane.TOP || tabsLocation == JTabbedPane.BOTTOM ? JTabbedPane.HORIZONTAL : JTabbedPane.VERTICAL;
scrollPane = new JScrollPane();
controls = new ControlsToolbar();
lblFullPath.setBorder( BorderFactory.createEmptyBorder( 0, 3, 2, 3) );
Font defaultFont = lblFullPath.getFont();
lblFullPath.setFont( defaultFont.deriveFont( defaultFont.getSize2D()-2 ) );
JPanel controlsPanel = new JPanel( new BorderLayout() );
controlsPanel.setOpaque( false );
if( TabTableUI.IS_AQUA ) {
Color backColor = UIManager.getColor( "NbSplitPane.background" ); //NOI18N
if( null != backColor ) {
setBackground( backColor );
setOpaque( true );
}
Color white = Color.white;
white = white.darker();
lblFullPath.setForeground(white);
}
switch( tabsLocation ) {
case JTabbedPane.TOP:
case JTabbedPane.BOTTOM:
add( scrollPane, BorderLayout.CENTER );
controlsPanel.add( controls, BorderLayout.NORTH );
add( controlsPanel, BorderLayout.EAST );
if( Settings.getDefault().isShowFullPath() )
add( lblFullPath, BorderLayout.SOUTH );
break;
case JTabbedPane.LEFT:
case JTabbedPane.RIGHT:
add( scrollPane, BorderLayout.CENTER );
controlsPanel.add( controls, BorderLayout.EAST );
add( controlsPanel, BorderLayout.NORTH );
break;
default:
throw new IllegalArgumentException( "Invalid orientation: " + tabsLocation );
}
configureScrollPane( scrollPane );
scrollLeft = new ScrollAction( scrollPane, tabsLocation, true );
scrollRight = new ScrollAction( scrollPane, tabsLocation, false );
controls.add( ButtonFactory.createScrollLeftButton( scrollLeft ) );
controls.add( ButtonFactory.createScrollRightButton( scrollRight ) );
addMouseWheelListener( this );
projectsListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
repaint();
}
};
fullPathListener = new ChangeListener() {
@Override
public void stateChanged( ChangeEvent e ) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateFullPath();
}
});
}
};
tabModel.addChangeListener(fullPathListener);
}
/**
* {@inheritDoc}
*/
public boolean isInState(JComponent c) {
return (c instanceof JTabbedPane && ((JTabbedPane) c).getTabPlacement() == JTabbedPane.TOP);
}
public TabTable( TabDataModel tabModel, int tabsLocation ) {
this( TabTableModel.create(tabModel, tabsLocation),
tabsLocation == JTabbedPane.TOP || tabsLocation == JTabbedPane.BOTTOM ? JTabbedPane.HORIZONTAL : JTabbedPane.VERTICAL );
this.tabsLocation = tabsLocation;
}
@Override
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
renderer.clear();
Rectangle rect = table.getCellRect( row, column, true );
renderer.setSize( rect.width, rect.height );
if( value instanceof TabData ) {
TabData tab = ( TabData ) value;
String text = tab.getText();
Icon icon = tab.getIcon();
Color colBackground = isSelected ? table.getSelectionBackground() : table.getBackground();
Color colForeground = isSelected ? table.getSelectionForeground() : table.getForeground();
boolean isActive = (activeBackground != null || underlineColor != null)
? TabbedImpl.isActive(table) : false;
if (!isSelected && isActive && activeBackground != null) {
colBackground = activeBackground;
}
for( TabDecorator td : decorators ) {
Color c = td.getBackground( tab, isSelected );
if( null != c )
colBackground = c;
c = td.getForeground( tab, isSelected );
if( null != c )
colForeground = c;
String s = td.getText( tab );
if( null != s )
text = s;
Icon i = td.getIcon( tab );
if( null != i ) {
icon = i;
}
}
boolean isHover = (hoverBackground != null && TabTableUI.isHover(table, row, column));
if (isHover) {
colBackground = hoverBackground;
}
renderer.label.setText( text );
renderer.label.setIcon( icon );
renderer.label.setFont( table.getFont() );
renderer.setBackground( colBackground );
renderer.label.setForeground( colForeground );
renderer.tabData = tab;
renderer.isSelected = isSelected;
renderer.isActive = isActive;
renderer.tabsLocation = (table instanceof TabTable) ? ((TabTable)table).getTabsLocation() : JTabbedPane.TOP;
if( table instanceof TabTable ) {
TabTable tabTable = ( TabTable ) table;
if( isClosable(tab) ) {
boolean inCloseButton = tabTable.isCloseButtonHighlighted( row, column );
renderer.closeButton.setVisible( true );
renderer.closeButton.getModel().setRollover( inCloseButton );
renderer.closeButton.getModel().setArmed( inCloseButton );
} else {
renderer.closeButton.setVisible( false );
}
}
}
return renderer;
}
/**
* Creates a new graph tab component.
*
* @param parent Parent window of the tab component.
*/
public JGraphTab(final CGraphWindow parent) {
super(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
m_parent = Preconditions.checkNotNull(parent, "IE01638: Parent argument can not be null");
}