在我的项目中,如果用户调整框架大小或屏幕分辨率较低,那么包含所有信息的JPanel将比JFrame大。添加jscrollpane,其中JPanel大于JFrame
通过的示例代码方式:
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class scroll{
public static void main(String[] args) {
JFrame frame = new JFrame("Example");
frame.setSize(500, 500);
frame.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(Color.BLACK);
panel.setBounds(5, 5, 450, 600);
frame.add(panel);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
有人能亲切地解释如何添加一个JScrollPane为此,对这里的外观和更广泛的网络,但似乎无法找到这个答案或教程。
也许你应该使用frame.setContentPane(面板),而不仅仅是frame.add(面板) – Hejun
@Hejun:'的JFrame :: add'转发到内容窗格。 – trashgod
@mainsworth:不要使用'null'布局。 – trashgod