简体   繁体   English

我的表格程序有问题。 可以告诉我如何解决吗?

[英]I have a problem with my table program. Could one tell me how to solve it?

We have to make a program which is a little bit like excel. 我们必须制作一个有点像excel的程序。 Now I have the problem, in that I want to make a field of 999 columns and 999 rows. 现在,我遇到了一个问题,因为我想创建一个999列和999行的字段。 I already tried to just at 999*999 JTextField controls but that obviously needs very long and I get an exception that there is no memory left. 我已经尝试只使用999 * 999 JTextField控件,但是显然这需要很长时间,而且我得到一个例外,那就是没有剩余的内存。 How could I make that better? 我该如何做得更好? Should I try to only render these text fields which are in use or is there a better method to make a table? 我应该只渲染这些正在使用的文本字段,还是有更好的方法来制作表格?

Here is my code: 这是我的代码:

tablePanel = new JPanel();
tablePanel.setLayout(new GridBagLayout());
tablePanel.setSize(100, 30);
tablePanel.setBorder(null);

JScrollPane tableScroll = new JScrollPane(tablePanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//tableScroll.getVerticalScrollBar().setPreferredSize(new Dimension(0,0));
//tableScroll.getVerticalScrollBar().setUnitIncrement(25);
tableScroll.setBounds(0, 30, 30, this.getHeight());
table = new ArrayList<>();
for (int i = 0; i < 999; i++) {
    ArrayList<Component> column = new ArrayList<>();
    for (int j = 0; j < 999; j++) {
        JTextField field = new JTextField();
        field.setPreferredSize(new Dimension(100, 30));
        field.setBorder(null);
        field.setFocusCycleRoot(false);
        field.setFocusable(false);
        gbc.gridy = j;
        gbc.gridx = i;

        column.add(field);
        tablePanel.add(field, gbc);
    }
    table.add(column);
}

You can create a javax.swing.JTable like this: 您可以这样创建一个javax.swing.JTable

JTable table = new JTable(999,999); // creates a 999*999 table
TableCellEditor tce = table.getCellEditor();
// use tce to follow user

and use tce to follow what the user is doing with what cell. 并使用tce来跟踪用户在哪个单元格中所做的事情。

For a more in-depth tutorial about javax.swing.JTable s, see How to Use Tables 有关javax.swing.JTable的更深入的教程,请参见如何使用表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java for:each 循环问题不起作用,而 for 循环适用于同一程序。 谁能说出区别并告诉我为什么? - Java for:each loop problem doesn't work while for loop works on the same program. Can anybody tell the difference and tell me why? 谁能告诉我为什么我的程序不起作用? - Could anyone tell me why my program doesn't work? 我尝试使用多态性,但我的代码不能像我预期的那样工作,有人可以帮我解决这个问题吗? - I try to use polymorphism but my code does not work as i excpected, could anyone help me solve this problem? 我已经尝试安装 Flutter 几个小时但失败了。 请告诉我如何解决这个问题 - I have tried to install Flutter for hours but failed. PLease tell me how to solve this 无法运行我的java .exe程序。 我该如何解决? (“发生Java异常”)和JNI问题 - Can't run my java .exe program. How do I troubleshoot this ? (“A Java exception has occured”) and JNI problem 我被困在一个 Java 程序中。 我的程序是一对多右外连接 - I am stuck in a Java program. My program is One To Many Right Outer Join 有人能告诉我我做错了什么吗 - Can some one tell me what i have done wrong 我在将我的 Java 程序拆分为同一 class 中的单独方法时遇到问题,我可以就如何 go 提供一些建议吗? - I have a problem with splitting up my Java program into separate methods within the same class, could I have some advice on how to go about it? 如果我有选择操作,谁能告诉我如何测试我的骆驼路线? - Can anyone tell me how to test my Camel Route if I have a choice operation? 我已经搜索了每个帖子,但我无法解决我的错误 - I have searched every post but I could not solve my error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM