java - 从 Java Swing 组件中检索对象

标签 java swing

我一直致力于 Java Swing 项目,我需要检索创建面板的对象/实例,以便调用特定于该实例的简单保存方法。

您有一个带有 JTabbedPane 的 JFrame,它具有通过实例化一个构建 JPanel 并将其添加到 JTabbedPane 的类创建的选项卡,我需要从 JTabbedPane 上的选定 JPanel/选项卡中找到特定实例,然后调用它保存方法。

有什么想法吗? 感谢您的宝贵时间!

public class frame extends JFrame implements ActionListener{
 Builds a frame dubbed "frame" that is static.
 Builds a static JTabbedPane dubbed "pane"and adds it to the frame.
 Creates a button that creates a new instance of sheet.

 public void actionPerformed(MAGIC!){
  See if a button on the panel has been pressed and uses the currently selected tab to locate the correct instance of sheet to run it's save method.
 }
}

public class sheet extends JPanel{
 In constructor makes a JPanel and adds it to "pane"

 Describes a save method that outputs a variable unique to the instance.
}

最佳答案

我发现我需要做的就是将新的选项卡对象存储在 ArrayList derp 中。感谢你们的尝试,虽然伙计们!

关于java - 从 Java Swing 组件中检索对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9959393/

相关文章:

javax.servlet.HttpServletRequest.getContentLength() 仅返回 int

java - 带递归的 printStars 方法

java - 使用 ZXing 在 Android 上编码联系人信息 (MeCard)

java - 在按下 JAVA 时更改 JButton 的 BG 颜色

java - 设计模式 - 使用通用对象来更新 GUI

java - 如何在 JTextPane 页脚中打印总页数?

java - 部署在 Tomcat 上的 Spring Boot Rest API 提供 404,但独立运行一切正常

Java解析网站

java - 在 JEditorPane 中动态添加 rtf 文件的超链接

java - JPanel 没有出现在 JFrame 上