下面列出了怎么用javax.swing.JSplitPane的API类实例代码及写法,或者点击链接到github查看源代码。
/**
*
*/
public UnitsPanel(PreferencesExt prefs) {
this.prefs = prefs;
unitDataset = new UnitDatasetCheck((PreferencesExt) prefs.node("unitDataset"));
unitConvert = new UnitConvert((PreferencesExt) prefs.node("unitConvert"));
dateFormatMark = new DateFormatMark((PreferencesExt) prefs.node("dateFormatMark"));
split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, unitConvert, dateFormatMark);
split2.setDividerLocation(prefs.getInt("splitPos2", 500));
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(unitDataset), split2);
split.setDividerLocation(prefs.getInt("splitPos", 500));
setLayout(new BorderLayout());
add(split, BorderLayout.CENTER);
}
public void init() {
tableIcon = FormUtils.getIcon(tableIcon, DEFAULT_TABLE_ICON);
for (TableEditor<?> editor : editors)
editor.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
list = new JList(editors);
list.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(-1);
JScrollPane scroll = new JScrollPane(list);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll, editorPanel);
getContentPane().add(split);
list.addListSelectionListener(this);
list.setCellRenderer(new ListCellRenderer());
list.setSelectedIndex(0);
setSize(800, 600);
}
/**
* Creates a data type synchronization dialog
* @param plugin the data type manager plug-in
* @param synchronizer the data type synchronizer for synchronizing a program and archive.
* @param list the list of data types to be displayed to the user.
* @param commit true means data types from the program data types are to be committed
* back to the associated data types in the archive. false means update the program data
* types with changes that were made in the archive.
*/
public DataTypeSyncDialog(DataTypeManagerPlugin plugin, String clientName, String sourceName,
List<DataTypeSyncInfo> list, Set<DataTypeSyncInfo> preselectedInfos,
String operationName, String title) {
super(title, true);
this.plugin = plugin;
this.operationName = operationName;
syncPanel = new DataTypeSyncPanel(list, preselectedInfos, this);
comparePanel = new DataTypeComparePanel(clientName, sourceName);
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, syncPanel, comparePanel);
splitPane.setResizeWeight(0.6);
mainPanel = new JPanel(new BorderLayout());
mainPanel.add(splitPane, BorderLayout.CENTER);
addWorkPanel(mainPanel);
initialize();
createActions();
}
/**
* overrides to hardcode the size of the divider
* PENDING(jeff) - rewrite JSplitPane so that this ins't needed
*/
public void setDividerSize(int newSize) {
Insets insets = getInsets();
int borderSize = 0;
if (getBasicSplitPaneUI().getOrientation() ==
JSplitPane.HORIZONTAL_SPLIT) {
if (insets != null) {
borderSize = insets.left + insets.right;
}
}
else if (insets != null) {
borderSize = insets.top + insets.bottom;
}
if (newSize < pad + minimumThumbSize + borderSize) {
setDividerSize(pad + minimumThumbSize + borderSize);
} else {
vThumbHeight = hThumbWidth = newSize - pad - borderSize;
super.setDividerSize(newSize);
}
}
public static void main(String[] args) throws InterruptedException {
if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()){
throw new Error("unexpected traversal keys");
}
new JSplitPane() {
public void setFocusTraversalKeys(int id, Set keystrokes) {
keystrokes.clear();
super.setFocusTraversalKeys(id, keystrokes);
}
};
if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()) {
throw new Error("shared traversal keys");
}
KEYBOARD_DIVIDER_MOVE_OFFSET = -KEYBOARD_DIVIDER_MOVE_OFFSET;
ThreadGroup group = new ThreadGroup("$$$");
Thread thread = new Thread(group, new Test6657026());
thread.start();
thread.join();
}
public static void main(String[] args) throws InterruptedException {
if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()){
throw new Error("unexpected traversal keys");
}
new JSplitPane() {
public void setFocusTraversalKeys(int id, Set keystrokes) {
keystrokes.clear();
super.setFocusTraversalKeys(id, keystrokes);
}
};
if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()) {
throw new Error("shared traversal keys");
}
KEYBOARD_DIVIDER_MOVE_OFFSET = -KEYBOARD_DIVIDER_MOVE_OFFSET;
ThreadGroup group = new ThreadGroup("$$$");
Thread thread = new Thread(group, new Test6657026());
thread.start();
thread.join();
}
private void initializeComponent() {
setJMenuBar( createMenu() );
myVPLineChart = new DomLineChart(myEngine.getPlayers(), "VP");
myBarChart = new DomBarChart(myEngine.getPlayers());
myMoneyLineChart = new DomLineChart(myEngine.getPlayers(), "Money");
myTopSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, new JScrollPane(getControlPanel()), myVPLineChart.getChartPanel());
myBottomSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, myBarChart.getChartPanel(), myMoneyLineChart.getChartPanel());
myBigSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, myTopSplit, myBottomSplit);
myBigSplit.setResizeWeight(0.8);
myTopSplit.setResizeWeight(0.50);
myBottomSplit.setResizeWeight(0.5);
myBottomSplit.setDividerSize(5);
myBigSplit.setDividerSize(5);
myTopSplit.setDividerSize(5);
add(myBigSplit);
}
public void run() {
SunToolkit.createNewAppContext();
if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()) {
throw new Error("shared traversal keys");
}
JSplitPane pane = new JSplitPane();
pane.setUI(this);
createFocusListener().focusGained(null); // allows actions
test(pane, "positiveIncrement", 3);
test(pane, "negativeIncrement", 0);
}
protected JComponent createFileStuff() {
JSplitPane t = new JSplitPane(VERTICAL_SPLIT);
t.setResizeWeight(0.5);
t.setTopComponent(createTransferTable());
t.setBottomComponent(createFileopTable());
return t;
}
public RSFViewer2(final Engine engine) {
this.engine = engine;
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
((FileIEngineImpl) engine.getDeligate()).close();
} catch (IOException e1) {
e1.printStackTrace();
}
System.exit(0);
}
});
this.setTitle("Ramus files viewer sample 2");
JSplitPane pane = new JSplitPane();
pane.setLeftComponent(createQualifiersList());
pane.setRightComponent(createTreeView());
this.setContentPane(pane);
this.pack();
this.setSize(800, 600);
this.setLocationRelativeTo(null);
}
public void setDefaultValue(int _index) {
switch(_index) {
case 0 :
splitpanel.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
break;
case 1 :
splitpanel.setOneTouchExpandable(true);
break;
default :
super.setDefaultValue(_index-2);
break;
}
}
@Override
public final void actionPerformed(ActionEvent evt) {
final TopComponent tc = WindowManager.getDefault().getRegistry().getActivated();
if (tc != null) {
SplitAction.splitWindow(tc, JSplitPane.VERTICAL_SPLIT, -1);
}
}
@Override
public void init() {
Insets insets = new Insets(10, 10, 10, 10);
Dimension size = new Dimension(getWidth() / 2, getHeight());
JSplitPane pane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
create("Color", size, new MatteBorder(insets, RED)),
create("Icon", size, new MatteBorder(insets, this)));
pane.setDividerLocation(size.width - pane.getDividerSize() / 2);
add(pane);
}
/**
* Maps {@code JSplitPane.setLeftComponent(Component)} through queue
*/
public void setLeftComponent(final Component component) {
runMapping(new MapVoidAction("setLeftComponent") {
@Override
public void map() {
((JSplitPane) getSource()).setLeftComponent(component);
}
});
}
protected void prepareControls() {
JFrame frame = new JFrame("SplitPane Mixing");
JPanel p = new JPanel(new GridLayout());
p.setPreferredSize(new Dimension(500, 500));
propagateAWTControls(p);
sp1 = new JScrollPane(p);
JButton button = new JButton("JButton");
button.setBackground(Color.RED);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clicked = true;
}
});
sp2 = new JScrollPane(button);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp1, sp2);
splitPane.setOneTouchExpandable(false);
splitPane.setDividerLocation(150);
splitPane.setPreferredSize(new Dimension(400, 200));
frame.getContentPane().add(splitPane);
frame.pack();
frame.setVisible(true);
}
/**
* Invokes the <code>getMaximumDividerLocation</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 getMaximumDividerLocation(JSplitPane a) {
int returnValue =
((SplitPaneUI) (uis.elementAt(0))).getMaximumDividerLocation(a);
for (int i = 1; i < uis.size(); i++) {
((SplitPaneUI) (uis.elementAt(i))).getMaximumDividerLocation(a);
}
return returnValue;
}
private Container getMainContentContainer() {
// card pool
cardPoolDefs = filterPanel.getFilteredCards();
cardPoolTable = new CardTablePanelB(cardPoolDefs, generatePoolTitle(), false);
cardPoolTable.addMouseListener(new CardPoolMouseListener());
cardPoolTable.addCardSelectionListener(this);
cardPoolTable.setDeckEditorSelectionMode();
deckDefs = this.deck;
deckTable = new CardTablePanelB(deckDefs, generateDeckTitle(deckDefs), true);
deckTable.addMouseListener(new DeckMouseListener());
deckTable.addCardSelectionListener(this);
deckTable.setDeckEditorSelectionMode();
deckTable.showCardCount(true);
final JPanel deckPanel = new JPanel();
deckPanel.setOpaque(false);
deckPanel.setLayout(new MigLayout("insets 0, gap 0, flowy"));
deckPanel.add(buttonsPanel, "w 100%, h 40!");
deckPanel.add(deckTable, "w 100%, h 100%");
cardsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
cardsSplitPane.setOneTouchExpandable(false);
cardsSplitPane.setLeftComponent(cardPoolTable);
cardsSplitPane.setRightComponent(deckPanel);
cardsSplitPane.setResizeWeight(0.5);
cardsSplitPane.setDividerSize(14);
cardsSplitPane.setBorder(null);
cardsSplitPane.setOpaque(false);
cardsSplitPane.setDividerLocation(getDividerPosition());
// update deck stats
sideBarPanel.setDeck(this.deck);
return cardsSplitPane;
}
@Override
public void init() {
Insets insets = new Insets(10, 10, 10, 10);
Dimension size = new Dimension(getWidth() / 2, getHeight());
JSplitPane pane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
create("Color", size, new MatteBorder(insets, RED)),
create("Icon", size, new MatteBorder(insets, this)));
pane.setDividerLocation(size.width - pane.getDividerSize() / 2);
add(pane);
}
private Component getFirstComponent(JSplitPane splitPane) {
if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
return splitPane.getLeftComponent();
} else {
return splitPane.getTopComponent();
}
}
public void buildPanels() {
gameFrame = new GameFrame(this);
gameMenu = new GameMenu(this);
gameFrame.setJMenuBar(gameMenu);
gameToolbar = new GameToolbar(this);
boardRenderer = new BoardRenderer(getGameModel());
displayControlPanel = new DisplayControlPanel(this);
settingsControlPanel = new RulesControlPanel(this);
statsPanel = new StatsPanel(this);
tipsPanel = new TipsPanel(this);
ScrollPanel scrollPanel = getScrollPanel();
JTabbedPane rightPane = new JTabbedPane();
rightPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
rightPane.addTab("Display", wrapInScrolPane(displayControlPanel));
rightPane.addTab("Rules", wrapInScrolPane(settingsControlPanel));
rightPane.addTab("Stats", statsPanel);
rightPane.addTab("Tips", tipsPanel);
JPanel gamePanel = new JPanel(new BorderLayout());
gamePanel.add(scrollPanel, BorderLayout.CENTER);
gamePanel.add(gameToolbar, BorderLayout.NORTH);
splitPane = new JSplitPane();
splitPane.setResizeWeight(1);
splitPane.setOneTouchExpandable(true);
splitPane.setLeftComponent(gamePanel);
splitPane.setRightComponent(rightPane);
gameFrame.add(splitPane);
}
protected void resizeSplit( int orientation, int splitSize, int nonResizingSize ) {
if( orientation == JSplitPane.HORIZONTAL_SPLIT )
split.setSize( splitSize, nonResizingSize );
else
split.setSize( nonResizingSize, splitSize );
testWindow.getContentPane().add( split );
split.validate();
}
public AbstractScriptPanel(final LayoutManager layout) {
super(layout);
languageBox = new LanguageBox(getManager());
languageBox.addActionListener(new InternalLanguageBoxListener());
m_inputPane.setEditable(true);
m_inputPane.setBackground(new Color((float) .97, (float) .97, 1));
m_inputPane.setFont(new Font(GuiHelper.getMonospaceFont(), 0, 13));
m_OutputPane.setDocument(m_PythonStdoutDocument);
m_OutputPane.setEditable(false);
m_OutputPane.setBackground(new Color((float) .97, (float) .97, 1));
final JScrollPane inputScrollPane = new JScrollPane(m_inputPane);
final TitledBorder inputAreaBorder =
new TitledBorder(new LineBorder(Color.LIGHT_GRAY, 1, true), "Command Line");
inputScrollPane.setBorder(inputAreaBorder);
inputScrollPane.setPreferredSize(new Dimension(600, 200));
final JScrollPane m_OutputScrollPane = new JScrollPane(m_OutputPane);
final TitledBorder outputAreaBorder =
new TitledBorder(new LineBorder(Color.LIGHT_GRAY, 1, true), "Output");
m_OutputScrollPane.setBorder(outputAreaBorder);
m_OutputScrollPane.setPreferredSize(new Dimension(600, 200));
add(languageBox, BorderLayout.NORTH);
add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, inputScrollPane, m_OutputScrollPane));
}
private int convertPosition(LayoutConstraints desc) {
if (desc != null) {
Object position = desc.getConstraintsObject();
if (JSplitPane.LEFT.equals(position) || JSplitPane.TOP.equals(position))
return 0;
if (JSplitPane.RIGHT.equals(position) || JSplitPane.BOTTOM.equals(position))
return 1;
}
return -1;
}
/**
* Overridden to handle our layout requirements
*/
public void doLayout() {
Component[] c = getComponents();
if (c.length > 0 && getWidth() >= 0 && getHeight() >= 0) {
Insets ins = getInsets();
c[0].setBounds(ins.left, ins.top, getWidth() - (ins.right + ins.left), getHeight() - ins.top + ins.bottom);
if (c[0] instanceof JSplitPane && Boolean.TRUE.equals(firstSplit)) {
JSplitPane pane = (JSplitPane) c[0];
pane.setDividerLocation(0.80f);
pane.resetToPreferredSizes();
JComponent dc = findDescriptionComponent();
if (dc != null) {
if (dc.getHeight() > 0) {
firstSplit = Boolean.FALSE;
}
} else {
firstSplit = Boolean.FALSE;
}
}
if (c.length > 1) {
throw new IllegalStateException("Hmm, something is wrong: " + Arrays.asList(c));
}
}
}
public ProcessingComponent() {
mainPanel = new JPanel(new BorderLayout());
mainPanel.setPreferredSize(new Dimension(600, 400));
cbDiffMSn = GUIUtils.addCheckbox(mainPanel,
"Use different settings for " + MSLevel.MSONE.toString() + " and "
+ MSLevel.MSMS.toString(),
this, "CBX_DIFFMSN",
"If enabled, MS^1 and MS^n processing will use different parameters. The currently used settings are highlighted in green.");
cbDiffMSn.setSelected(
DataPointProcessingManager.getInst().getProcessingParameters().isDifferentiateMSn());
mainPanel.add(cbDiffMSn, BorderLayout.NORTH);
setupTreeViews();
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tvProcessing, tvAllModules);
initTreeListeners();
mainPanel.add(split, BorderLayout.CENTER);
split.setDividerLocation(300);
buttonPanel = new JPanel(new FlowLayout());
GUIUtils.addButton(buttonPanel, "Add", null, this, "BTN_ADD");
GUIUtils.addButton(buttonPanel, "Remove", null, this, "BTN_REMOVE");
GUIUtils.addButton(buttonPanel, "Set parameters", null, this, "BTN_SET_PARAMETERS");
GUIUtils.addButton(buttonPanel, "Load", null, this, "BTN_LOAD");
GUIUtils.addButton(buttonPanel, "Save", null, this, "BTN_SAVE");
// GUIUtils.addButton(buttonPanel, "Set Default...", null, this,
// "BTN_SET_DEFAULT");
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
chooser = new FileChooser();
chooser.setTitle("Select Processing Queue File");
chooser.getExtensionFilters().add(new ExtensionFilter("XML files", XML_EXTENSION));
SwingUtilities.invokeLater(() -> {
this.setContent(mainPanel);
});
}
private JSplitPane createUnderPane(JTree tree) {
JTextArea toStringArea = new JTextArea();
toStringArea.setLineWrap(true);
toStringArea.setEditable(false);
tree.addTreeSelectionListener(new ToStringListener(toStringArea));
JSplitPane result = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
new JScrollPane(tree),
new JScrollPane(toStringArea));
result.setOneTouchExpandable(true);
result.setDividerSize(8);
result.setDividerLocation(0.8);
return result;
}
private void initLayout() {
JSplitPane splitPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPanel.setDividerLocation(230);
JScrollPane scrTextArea = new JScrollPane();
scrTextArea.setBorder(new TitledBorder(new LineBorder(Color.BLACK),
Bundle.HINT_ChartTopComponent_SCRPanelTitle(),
TitledBorder.CENTER,TitledBorder.TOP));
scrTextArea.setPreferredSize(new Dimension(220, 300));
scrTextArea.setViewportView(detailedLog);
JScrollPane scrTable = new JScrollPane();
scrTable.setBorder(new TitledBorder(new LineBorder(Color.BLACK),
Bundle.HINT_ChartTopComponent_SCRPanelTable(),
TitledBorder.CENTER,TitledBorder.TOP));
scrTable.setViewportView(cellChangesTable);
JScrollPane scrTC = new JScrollPane();
scrTC.setViewportView(panelChart);
splitPanel.add(scrTextArea);
splitPanel.add(scrTable);
JPanel tmp = new JPanel(new BorderLayout());
tmp.add(panelChart,BorderLayout.NORTH);
tmp.add(splitPanel,BorderLayout.CENTER);
JScrollPane tmpScr = new JScrollPane();
tmpScr.setViewportView(tmp);
add(tmpScr,BorderLayout.CENTER);
}
public void mouseReleased(MouseEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
((JSplitPane) getFirstComponent()).setResizeWeight(firstResizeWeight);
((JSplitPane) getSecondComponent()).setResizeWeight(secondResizeWeight);
}
});
}
private static void tweakSplitPaneUI(JSplitPane splitPane) {
splitPane.setOpaque(false);
splitPane.setBorder(null);
splitPane.setDividerSize(3);
if (!(splitPane.getUI() instanceof BasicSplitPaneUI)) {
return;
}
BasicSplitPaneDivider divider = ((BasicSplitPaneUI) splitPane.getUI()).getDivider();
if (divider != null) {
divider.setBorder(null);
}
}
private void init() {
setLayout(new BorderLayout());
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setOneTouchExpandable(true);
splitPane.setBottomComponent(objectTable);
TreeSearch tSearch = TreeSearch.installForOR(objectTree.getTree());
splitPane.setTopComponent(tSearch);
splitPane.setResizeWeight(.5);
splitPane.setDividerLocation(.5);
add(splitPane);
}