gpt4 book ai didi

java - 使用 JScrollPane 和 JPanel 创建可滚动的 JFrame

转载 作者:行者123 更新时间:2023-12-01 18:38:45 25 4
gpt4 key购买 nike

在寻找解决方案时,我在 StackOverflow 的所有答案中发现了几乎相同的想法。但一切都不起作用,我需要帮助我找到该特殊代码部分的解决方案。

//Create a JTabbedPane for 2 tabs
mainTabs = new JTabbedPane(JTabbedPane.TOP);

//Create the first tab
reportingTabs = new JTabbedPane(JTabbedPane.TOP);

// editor is an object created from a class inherited form JPanel
editor = new GraphEditor();

//Create a JMenuBar
EditorMenuBar menuBar = new EditorMenuBar(editor);

//Create a JFrame for the editor
editorFrame = editor.createFrame();


//Create a JPanel object to contain bothe the JMenubar and the editor JFrame
JPanel editorPanel = new JPanel(new BorderLayout());

//Here the solution, creating a JScrollPane to contain only the editor JFrame to be scrolled
JScrollPane editorScroll = new JScrollPane();

//Adding the JMenuBar and the editor JFrame to the JPanel
editorPanel.add(menuBar, BorderLayout.NORTH);
editorPanel.add(editorFrame.getContentPane());

//Involve the JPanel into the JScrollPane
editorScroll.add(editorPanel);


//Adding the tabs to the main JFrame
maingui.getContentPane().add(mainTabs);

//Adding the JScrolledPane to a tab
mainTabs.addTab("Editor", editorScroll);

结果是maingui中没有JFrame。 (没有 SCrollPane 解决方案,它会正确显示)

最佳答案

完全删除 editorScroll 变量并替换

     mainTabs.addTab("Editor", editorScroll); 

     mainTabs.addTab("Editor", new JScrollPane(editorPanel));

应该可以用...

关于java - 使用 JScrollPane 和 JPanel 创建可滚动的 JFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20775817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com