为了账号安全,请及时绑定邮箱和手机立即绑定

JTable未显示在JFrame(Java)上

JTable未显示在JFrame(Java)上

智慧大石 2019-10-22 21:30:50
我有一个问题,JFrame没有显示JTable添加到它。我已经尝试过getContentPane().add(..),我已切换为仅添加以使代码更短一些。任何帮助都超过了感激!package com.embah.Accgui;import java.awt.*;import javax.swing.*;public class accCreator extends JFrame {private String[] columnNames = {"Username", "Password", "Members", "World"};private Object[][] data = {{"b", "b", "b", "b"},                          { "e", "e", "e", "e"}};    private JTable tbl_Accounts;    private JScrollPane scrollPane;    private JLabel lbl_Account = new JLabel();    private JLabel lbl_Username = new JLabel();    private JLabel lbl_Password = new JLabel();    private JLabel lbl_Homeworld = new JLabel();    private JButton btn_Select = new JButton();    private JButton btn_Addacc = new JButton();    private JButton btn_Delacc = new JButton();    private JTextArea txt_Username = new JTextArea();    private JTextArea txt_Password = new JTextArea();    private JTextArea txt_Homeworld = new JTextArea();    private JCheckBox cbox_Members = new JCheckBox();    private JCheckBox cbox_RanWrld = new JCheckBox();public accCreator() {    setLayout(null);    setupGUI();    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}void setupGUI() {    tbl_Accounts = new JTable(data, columnNames);    tbl_Accounts.setLocation(5, 30);    tbl_Accounts.setPreferredScrollableViewportSize(new Dimension(420, 250));    tbl_Accounts.setFillsViewportHeight(true);    tbl_Accounts.setVisible(true);    add(tbl_Accounts);    scrollPane = new JScrollPane(tbl_Accounts);    add(scrollPane);    lbl_Account.setLocation(4, 5);    lbl_Account.setSize(100, 20);    lbl_Account.setText("Select Account:");    add(lbl_Account);    lbl_Username.setLocation(5, 285);    lbl_Username.setSize(70, 20);    lbl_Username.setText("Username:");    add(lbl_Username);    lbl_Password.setLocation(5, 310);    lbl_Password.setSize(70, 20);    lbl_Password.setText("Password:");    add(lbl_Password);
查看完整描述

2 回答

?
梵蒂冈之花

TA贡献1900条经验 获得超5个赞

不能说谢谢你们,对不起,我这么固执,无法早日听你们说。我只是想制作一个不错的GUI,而我整天都在努力使它正常工作,我非常沮丧。Frak,您向我展示了setLayout(null)非常糟糕,不应该这样做。非常感谢您的投入和帮助!我非常感谢你们的帖子!

查看完整回答
反对 回复 2019-10-22
  • 2 回答
  • 0 关注
  • 695 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信