JFrame with JSplitpane
时间: 2023-07-08 17:42:29 浏览: 97
Sure, I can help you with that! Here is an example code snippet for creating a JFrame with JSplitPane:
```
import javax.swing.*;
public class MyFrame extends JFrame {
public MyFrame() {
// Set JFrame properties
setTitle("JFrame with JSplitPane");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create JSplitPane
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(250);
splitPane.setResizeWeight(0.5);
// Add components to JSplitPane
JPanel leftPanel = new JPanel();
JPanel rightPanel = new JPanel();
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(rightPanel);
// Add JSplitPane to JFrame
add(splitPane);
// Display JFrame
setVisible(true);
}
public static void main(String[] args) {
new MyFrame();
}
}
```
This code creates a horizontal `JSplitPane` with two `JPanel` components and adds it to a `JFrame`. You can adjust the `setDividerLocation` and `setResizeWeight` methods to customize the appearance of the `JSplitPane`. Let me know if you have any further questions!
阅读全文