【发布时间】:2014-02-25 07:03:52
【问题描述】:
我有这个类和另一个类连接到数据库并向我显示一个数据库表这部分程序工作得很好下面解释的问题,但是没有:
import java.awt.Color;
import java.awt.event.*;
import java.sql.SQLException;
import javax.swing.*;
public class ManagerInterface {
public static JFrame ManagerInterface = new JFrame("Manager Interface");
public ManagerInterface() {
StartInterfaceGUI();
}
public static JFrame getframe() {
return ManagerInterface;
}
private void StartInterfaceGUI() {
ManagerInterface.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ManagerInterface.setSize(1600, 900);
new ShowEmployee();
ManagerInterface.setVisible(true);
}
}
public static void main(String []args)
{
new ManagerInterface();
}
还有这个类:
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import GUIManager.ManagerInterface;
public class ShowEmployee {
public static JInternalFrame frame = new JInternalFrame();
public JTable table = new JTable();
public JFrame mainframe = new JFrame();
public ShowEmployee() {
frame.add(table);
JScrollPane scroll = new JScrollPane(table);
frame.getContentPane().add(scroll, BorderLayout.SOUTH);
frame.setTitle("Employees");
frame.setResizable(true);
frame.setClosable(true);
frame.setMaximizable(true);
frame.setIconifiable(true);
frame.setSize(650, 400);
frame.pack();
frame.setVisible(true);
/* mainframe.add(frame);
mainframe.setSize(650, 400); //adding frame inside mainframe defined in this class
mainframe.pack();
mainframe.setVisible(true);*/
//ManagerInterface.getframe().add(frame); //adding the internalframe to manager interface frame
}
}
我使用 ManagerInterface 作为 ShowEmployee 的容器,这样:
在 ManagerInterface 中我调用了 JFrame
ShowEmployee 类由一个 JInternalFrame 表示,在其上添加一个 JTable。
- 我将 JInternalFrame 添加到 managerInterface 类 的 frame,它由 ManagerInterface.getframe.add 行定义。 (frame),插入 ShowEmployee。
问题如下:
如果我在 ShowEmployee 内定义一个框架(在本例中为大型机)并添加 internalframe 我会看到:
但是,如果我将 JInternalFrame 添加到框架 ManagerInterface 我会看到:
也就是说,我没有看到ScrollPane所代表的表格的属性行,在frame managerInterface里面是看不到的, 我以这种方式定义滚动窗格,在 ShowEmployee 中定义。 JScrollPane 滚动 = 新 JScrollPane (table); frame.getContentPane (.) add (scroll BorderLayout.SOUTH);
【问题讨论】:
-
无关:请学习java命名约定并遵守。
-
所有这些代码似乎真的没有必要。尤其是当您使用我们可能必须或可能不必尝试运行示例的第三方库时。而且这个问题似乎与数据库没有任何关系。您可以使用标题的静态名称轻松创建a Minimal, Complete, Tested and Readable example。为了尽快获得更好的帮助,请尝试创建一个 MCTRE,如链接所示
-
代码已编辑,@peeskillet
-
您的代码似乎有一个 main 方法在任何类之外的任何地方悬空,我不确定除了过度使用和错过之外还有什么其他问题- 使用静力学。您可能想解决这个问题,只发布真实代码,即编译和运行的代码。
-
请务必阅读有关 internalFrames 的教程章节(该教程在 swing 标签 wiki 中引用) - 它们不旨在添加到除 JDesktopPane 之外的任何其他内容中