java如何向JTabbedPane添加滚动条
我对我的java非常熟悉,在制作GUI的几次过程中,我总是在eclipse中使用windowbuilder,但我想为cytoscape创建一个插件,它可以与java一起工作
现在我有一个jframe和一个jtabbedpane(有两个选项卡)。因此,在第二个选项卡中,我想添加超出框架原始大小的元素,因此我添加了一个jscrollpane(包括setPreferredSize()),但是当添加超出边框的元素时,什么都看不见,所以我不理解。 出于这个原因,我的问题是,哪种方法是制作带有向下滚动条的面板的最佳方法
这是我的基本代码
package org.cytoscape.sample.internal;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class GUI {
JFrame frame;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GUI window = new GUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public GUI() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame("simple test");
frame.setResizable(false);
frame.setBounds(100, 100, 415, 650);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnNewMenu = new JMenu("Help");
menuBar.add(mnNewMenu);
JMenuItem mntmNewMenuItem = new JMenuItem("Manual");
mnNewMenu.add(mntmNewMenuItem);
frame.getContentPane().setLayout(null);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(0, 0, 415, 530);
frame.getContentPane().add(tabbedPane);
/**********************************
*
* Here start the first tab
*
***********************************/
JPanel mainPanel = new JPanel();
tabbedPane.addTab("first tab", null, mainPanel, null);
mainPanel.setLayout(null);
/**********************************
*
* Here start the second tab
*
***********************************/
JScrollPane configPanelHM = new JScrollPane();
tabbedPane.addTab("second tab", null, configPanelHM, null);
configPanelHM.setLayout(null);
configPanelHM.setPreferredSize(new Dimension(100,100));
/**********************************
*
* Run Button
*
***********************************/
JButton btnRunWeon = new JButton("Run");
btnRunWeon.setBounds(0, 535, 409, 47);
frame.getContentPane().add(btnRunWeon);
}
}
共 (0) 个答案