我有这个Frame
课程;如您所见,我向splitPane
课程添加了Frame
:
public class Frame extends JFrame {
private static final long serialVersionUID = 1L;
private static final int X_AXIS = 175;
private static final int Y_AXIS = 25;
private static final int WIDTH= 930;
private static final int HEIGHT = 600;
private SplitPane splitPane;
public Frame() {
this.setTitle("My Frame");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(X_AXIS,Y_AXIS,WIDTH,HEIGHT);
splitPane = new SplitPane();
this.getContentPane().add(splitPane);
}
}
这是SplitPane
课程。我在左边添加了JScrollPane
:
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
public class SplitPane extends JSplitPane{
private static final long serialVersionUID = 1L;
private static final int SPLIT_WEIGHT = 250;
private JScrollPane leftPanel;
public SplitPane() {
leftPanel = new LeftPanel();
this.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
this.setDividerLocation(SPLIT_WEIGHT);
this.setLeftComponent(leftPanel);
}
}
最后这是LeftPanel
class:
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneLayout;
public class LeftPanel extends JScrollPane{
private static final long serialVersionUID = 1L;
public LeftPanel() {
this.setLayout(new ScrollPaneLayout());
JButton button = new JButton("Hello World!");
this.add(button);
}
}
该按钮不会出现。
如何才能显示我的按钮"Hello World!"
?