下面列出了javax.swing.JSplitPane#setPreferredSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initView() {
this.setLayout(new GridLayout(1, 1));
if (roomId == null) {
messagePanel.setVisible(false);
messageEditorPanel.setVisible(false);
DebugUtil.debug("roomId == null");
}
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
// splitPane.setBorder(new RCBorder(RCBorder.BOTTOM,
// Colors.LIGHT_GRAY));
splitPane.setBorder(null);
// splitPane.setUI(new BasicSplitPaneUI());
// BasicSplitPaneDivider divider = (BasicSplitPaneDivider)
// splitPane.getComponent(0);
// divider.setBackground(Colors.FONT_BLACK);
// divider.setBorder(null);
splitPane.setOneTouchExpandable(false);
splitPane.setDividerLocation(450);
// splitPane.setResizeWeight(0.1);
splitPane.setDividerSize(2);
splitPane.setTopComponent(messagePanel);
splitPane.setBottomComponent(messageEditorPanel);
splitPane.setPreferredSize(new Dimension(MainFrame.DEFAULT_WIDTH, MainFrame.DEFAULT_HEIGHT));
// add(splitPane, new GBC(0, 0).setFill(GBC.BOTH).setWeight(1, 4));
// add(splitPane, new GBC(0, 0).setFill(GBC.BOTH).setWeight(1, 10));
add(splitPane);
// add(messagePanel, new GBC(0, 0).setFill(GBC.BOTH).setWeight(1, 4));
// add(messageEditorPanel, new GBC(0, 1).setFill(GBC.BOTH).setWeight(1,
// 1));
}
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);
}
/**
* @return Window components.
*/
@Override
protected Component createComponents() {
JPanel panel = new JPanel(new GridBagLayout());
// Initialize constraints
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = new Insets(2, 2, 2, 2);
constraints.ipadx = 0;
constraints.ipady = 0;
constraints.weightx = 0;
constraints.weighty = 0;
// Contents
constraints.fill = GridBagConstraints.BOTH;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.weightx = 1;
constraints.weighty = 1;
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
split.setLeftComponent(createLinksComponents());
split.setRightComponent(createAutomaticFixingComponents());
split.setPreferredSize(new Dimension(1000, 700));
split.setMinimumSize(new Dimension(200, 200));
split.setResizeWeight(0.0);
split.setDividerLocation(200 + split.getInsets().left);
panel.add(split, constraints);
constraints.gridy++;
updateComponentState();
return panel;
}
/**
* Constructor.
* @param chart
*/
public ImageTreePanel(ImageChart chart[]) {
super(new GridLayout(1, 0));
this.chart = chart;
//Create the nodes.
DefaultMutableTreeNode top
= new DefaultMutableTreeNode("Images");
imgPanel = new JPanel();
imgPanel.setLayout(new GridLayout(1, 0));
createNodes(top);
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
tree.setSelectionRow(1);
tree.addTreeSelectionListener(this);
ImageIcon leafIcon = new ImageIcon("icon/img.png");
if (leafIcon != null) {
DefaultTreeCellRenderer renderer
= new DefaultTreeCellRenderer();
renderer.setLeafIcon(leafIcon);
tree.setCellRenderer(renderer);
}
imgPanel.updateUI();
JScrollPane treeView = new JScrollPane(tree);
treeView.setMinimumSize(new Dimension(100, 50));
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(imgPanel);
splitPane.setDividerLocation(100);
splitPane.setPreferredSize(new Dimension(500, 300));
add(splitPane);
}
public TreeDemo() {
super(new GridLayout(1,0));
//Create the nodes.
DefaultMutableTreeNode top =
new DefaultMutableTreeNode("The Java Series");
createNodes(top);
//Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
//Listen for when the selection changes.
tree.addTreeSelectionListener(this);
if (playWithLineStyle) {
System.out.println("line style = " + lineStyle);
tree.putClientProperty("JTree.lineStyle", lineStyle);
}
//Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree);
//Create the HTML viewing pane.
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
//Add the scroll panes to a split pane.
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(htmlView);
Dimension minimumSize = new Dimension(100, 50);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(100);
splitPane.setPreferredSize(new Dimension(500, 300));
//Add the split pane to this panel.
add(splitPane);
}
public TreeDemo() {
super(new GridLayout(1, 0));
// Create the nodes.
DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
createNodes(top);
// Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
// Listen for when the selection changes.
tree.addTreeSelectionListener(this);
if (playWithLineStyle) {
System.out.println("line style = " + lineStyle);
tree.putClientProperty("JTree.lineStyle", lineStyle);
}
// Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree);
// Create the HTML viewing pane.
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
// Add the scroll panes to a split pane.
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(htmlView);
Dimension minimumSize = new Dimension(100, 50);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(100);
splitPane.setPreferredSize(new Dimension(500, 300));
// Add the split pane to this panel.
add(splitPane);
}
public TreeIconDemo() {
super(new GridLayout(1, 0));
// Create the nodes.
DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
createNodes(top);
// Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
// Set the icon for leaf nodes.
ImageIcon leafIcon = createImageIcon("images/middle.gif");
if (leafIcon != null) {
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(leafIcon);
tree.setCellRenderer(renderer);
} else {
System.err.println("Leaf icon missing; using default.");
}
// Listen for when the selection changes.
tree.addTreeSelectionListener(this);
// Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree);
// Create the HTML viewing pane.
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
// Add the scroll panes to a split pane.
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(htmlView);
Dimension minimumSize = new Dimension(100, 50);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(100); // XXX: ignored in some releases
// of Swing. bug 4101306
// workaround for bug 4101306:
// treeView.setPreferredSize(new Dimension(100, 100));
splitPane.setPreferredSize(new Dimension(500, 300));
// Add the split pane to this panel.
add(splitPane);
}
public TreeIconDemo2() {
super(new GridLayout(1, 0));
// Create the nodes.
DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
createNodes(top);
// Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
// Enable tool tips.
ToolTipManager.sharedInstance().registerComponent(tree);
// Set the icon for leaf nodes.
ImageIcon tutorialIcon = createImageIcon("images/middle.gif");
if (tutorialIcon != null) {
tree.setCellRenderer(new MyRenderer(tutorialIcon));
} else {
System.err.println("Tutorial icon missing; using default.");
}
// Listen for when the selection changes.
tree.addTreeSelectionListener(this);
// Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree);
// Create the HTML viewing pane.
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
// Add the scroll panes to a split pane.
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(htmlView);
Dimension minimumSize = new Dimension(100, 50);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(100); // XXX: ignored in some releases
// of Swing. bug 4101306
// workaround for bug 4101306:
// treeView.setPreferredSize(new Dimension(100, 100));
splitPane.setPreferredSize(new Dimension(500, 300));
// Add the split pane to this panel.
add(splitPane);
}
/**
* @return Window components.
*/
@Override
protected Component createComponents() {
JPanel panel = new JPanel(new GridBagLayout());
// Initialize constraints
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = new Insets(2, 2, 2, 2);
constraints.ipadx = 0;
constraints.ipady = 0;
constraints.weightx = 0;
constraints.weighty = 0;
// Page name
//constraints.gridwidth = 2;
panel.add(createPageComponents(), constraints);
constraints.gridy++;
// Contents
constraints.fill = GridBagConstraints.BOTH;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.weightx = 1;
constraints.weighty = 1;
JSplitPane splitLinks = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitLinks.setLeftComponent(createLinksComponents());
splitLinks.setRightComponent(createCheckWikiComponents());
splitLinks.setResizeWeight(1.0);
splitLinks.setDividerLocation(0.9);
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
split.setLeftComponent(splitLinks);
split.setRightComponent(createContentsComponents());
split.setPreferredSize(new Dimension(1200, 700));
split.setMinimumSize(new Dimension(200, 200));
split.setResizeWeight(0.0);
split.setDividerLocation(200 + split.getInsets().left);
panel.add(split, constraints);
constraints.gridy++;
updateComponentState();
return panel;
}
/**
* @return Window components.
*/
@Override
protected Component createComponents() {
createElements();
JPanel panel = new JPanel(new GridBagLayout());
// Initialize constraints
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = new Insets(2, 2, 2, 2);
constraints.ipadx = 0;
constraints.ipady = 0;
constraints.weightx = 0;
constraints.weighty = 0;
// Page name
//constraints.gridwidth = 2;
panel.add(createPageComponents(), constraints);
constraints.gridy++;
// Contents
constraints.fill = GridBagConstraints.BOTH;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.weightx = 1;
constraints.weighty = 1;
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
split.setLeftComponent(createLinksComponents());
split.setRightComponent(createContentsComponents());
split.setPreferredSize(new Dimension(1200, 700));
split.setMinimumSize(new Dimension(200, 200));
split.setResizeWeight(0.0);
split.setDividerLocation(200 + split.getInsets().left);
panel.add(split, constraints);
constraints.gridy++;
updateComponentState();
return panel;
}
@Override
protected JSplitPane createMainPanel() {
JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
mainPanel.setOneTouchExpandable(false);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double widthRatio = 0.5;
formWidth = Math.max((int) (Math.min(screenSize.width, MAX_4K_WIDTH) * widthRatio), MIN_WIDTH);
double heightRatio = 0.6;
int formHeight = Math.max((int) (Math.min(screenSize.height, MAX_4K_HEIGHT) * heightRatio), MIN_HEIGHT);
getJDialog().setMinimumSize(new Dimension(formWidth + 16, formHeight + 72));
// top panel first
JSplitPane topPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
topPanel.setOneTouchExpandable(false);
JPanel descriptorPanel = createDescriptorAndVariablesAndPreprocessingPanel();
Dimension topPanelDimension = new Dimension((int)((formWidth - 3 * DEFAULT_PADDING) * 0.5), (int)((formHeight - 3 * DEFAULT_PADDING) * 0.75));
descriptorPanel.setMinimumSize(topPanelDimension);
descriptorPanel.setPreferredSize(topPanelDimension);
topPanel.setLeftComponent(descriptorPanel);
JPanel configurationPanel = createToolInfoPanel();
configurationPanel.setMinimumSize(topPanelDimension);
configurationPanel.setPreferredSize(topPanelDimension);
topPanel.setRightComponent(configurationPanel);
topPanel.setDividerLocation(0.5);
// bottom panel last
JPanel bottomPannel = createParametersPanel();
Dimension bottomPanelDimension = new Dimension(formWidth - 2 * DEFAULT_PADDING, (int)((formHeight - 3 * DEFAULT_PADDING) * 0.25));
bottomPannel.setMinimumSize(bottomPanelDimension);
bottomPannel.setPreferredSize(bottomPanelDimension);
mainPanel.setTopComponent(topPanel);
mainPanel.setBottomComponent(bottomPannel);
mainPanel.setDividerLocation(0.75);
mainPanel.setPreferredSize(new Dimension(formWidth, formHeight));
mainPanel.revalidate();
return mainPanel;
}
public MainWindow(File fileFromCommandLine) {
configSaver = ConfigSaver.getLoadedInstance();
windowPosition = configSaver.getMainWindowPosition();
luytenPrefs = configSaver.getLuytenPreferences();
mainMenuBar = new MainMenuBar(this);
this.setJMenuBar(mainMenuBar);
this.adjustWindowPositionBySavedState();
this.setHideFindBoxOnMainWindowFocus();
this.setShowFindAllBoxOnMainWindowFocus();
this.setQuitOnWindowClosing();
this.setTitle(TITLE);
this.setIconImage(new ImageIcon(
Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/Luyten.png"))).getImage());
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
label = new JLabel();
label.setHorizontalAlignment(JLabel.LEFT);
panel1.setBorder(new BevelBorder(BevelBorder.LOWERED));
panel1.setPreferredSize(new Dimension(this.getWidth() / 2, 20));
panel1.add(label);
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
bar = new JProgressBar();
bar.setStringPainted(true);
bar.setOpaque(false);
bar.setVisible(false);
panel2.setPreferredSize(new Dimension(this.getWidth() / 3, 20));
panel2.add(bar);
model = new Model(this);
this.getContentPane().add(model);
JSplitPane spt = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, panel2) {
private static final long serialVersionUID = 2189946972124687305L;
private final int location = 400;
{
setDividerLocation(location);
}
@Override
public int getDividerLocation() {
return location;
}
@Override
public int getLastDividerLocation() {
return location;
}
};
spt.setBorder(new BevelBorder(BevelBorder.LOWERED));
spt.setPreferredSize(new Dimension(this.getWidth(), 24));
this.add(spt, BorderLayout.SOUTH);
if (fileFromCommandLine != null) {
model.loadFile(fileFromCommandLine);
}
try {
DropTarget dt = new DropTarget();
dt.addDropTargetListener(new DropListener(this));
this.setDropTarget(dt);
} catch (Exception e) {
Luyten.showExceptionDialog("Exception!", e);
}
fileDialog = new FileDialog(this);
fileSaver = new FileSaver(bar, label);
this.setExitOnEscWhenEnabled(model);
if (fileFromCommandLine == null || fileFromCommandLine.getName().toLowerCase().endsWith(".jar")
|| fileFromCommandLine.getName().toLowerCase().endsWith(".zip")) {
model.startWarmUpThread();
}
if(RecentFiles.load() > 0) mainMenuBar.updateRecentFiles();
}