我正在尝试创建一个pdf查看器,但我无法将选项卡与选项卡式窗格分开。我尝试了一切,但没有成功,
setSize(x, y)
调整面板的大小。但它也没有用。这是一个截图:
这里有一些代码:
class Main
{
public static void main(String args[]){
JFrame frame = new JFrame("Pdf Reader");
frame.setJMenuBar(new MenuBar());
frame.getContentPane().add(new ToolBar(), BorderLayout.NORTH);
frame.getContentPane().add(new LeftPanel(), BorderLayout.CENTER);
frame.getContentPane().add(new ViewPanel(), BorderLayout.EAST);
frame.setVisible(true);
frame.setSize(1000, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class LeftPanel extends JPanel
{
private JTabbedPane tabs;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JPanel panel4;
public LeftPanel(){
addTabs();
}
public void addTabs()
{
tabs = new JTabbedPane();
panel1 = new JPanel();
tabs.addTab("Thumbnails", panel1);
panel2 = new JPanel();
tabs.addTab("Annotations", panel2);
panel3 = new JPanel();
tabs.addTab("Bookmarks", panel3);
panel4 = new JPanel();
tabs.addTab("Search", panel4);
setLayout(new GridLayout(1, 1));
add(tabs, BorderLayout.CENTER);
}
}
class ViewPanel extends JPanel
{
private JLabel viewLabel;
public ViewPanel(){
viewLabel = new JLabel("Just a view...............................");
add(viewLabel);
}
}
答案 0 :(得分:0)
嗯,这就是我解决问题的方法。
//frame.getContentPane().add(new LeftPanel(), BorderLayout.CENTER);
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new LeftPanel(), new ViewPanel());
frame.getContentPane().add(pane);
frame.setVisible(true);
frame.setSize(1000, 700);
//frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
这很好。