Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 定位JTable_Java_Swing_Layout - Fatal编程技术网

Java 定位JTable

Java 定位JTable,java,swing,layout,Java,Swing,Layout,(我会说法语,所以我提前道歉) 我被我的申请卡住了。我试图正确定位JTable,但SetPosition或setBound不起作用 这就是我得到的: 我也尝试使用布局,但它没有改变任何东西。我还尝试将null布局设置为JFrame,但它导致所有内容消失 以下是JTable代码: public class STable { private JTable jTable; private Object[][] data; private String title[]

(我会说法语,所以我提前道歉)

我被我的申请卡住了。我试图正确定位JTable,但SetPosition或setBound不起作用

这就是我得到的:

我也尝试使用布局,但它没有改变任何东西。我还尝试将null布局设置为JFrame,但它导致所有内容消失

以下是JTable代码:

    public class STable
{
    private JTable jTable;
    private Object[][] data;
    private String title[];
    private int x, y;

    public STable(int x, int y)
    {
        //Location
        this.x = x;
        this.y = y;
    }

    public Object[][] getData()
    {
        return this.data;
    }

    public void setData(Object[][] data)
    {
        this.data = data;
    }

    public void setTitle(String title[])
    {
        this.title = title;
    }

    public JTable getJTable()
    {
        return this.jTable;
    }

    public JTable createTable()
    {
        this.jTable = new JTable(this.data, this.title);
        this.jTable.setLocation(this.x, this.y);
        return this.jTable;
    }
}
这是我的框架:

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.app.graphics.panels.MainP;
import com.app.utils.SButton;
import com.app.utils.STable;
import com.app.utils.WindowMover;

public class MainF extends JFrame implements ActionListener
{
    private static final long serialVersionUID = -3853419533053844386L;

    @SuppressWarnings("unused")
    private JPanel currentPanel;
    private MainP panel;

    private SButton exitB, hideB, homeB, userB, settingB;

    private BufferedImage icon;

    public MainF()
    {
        this.setTitle("DAMP");
        this.setContentPane(this.panel = new MainP());
        this.currentPanel = this.panel;

        //Icon
        try
        {
            icon = ImageIO.read(getClass().getResource("/ressources/icon.png"));
        }
        catch (IOException e1)
            { e1.printStackTrace(); }
        this.setIconImage(icon);

        this.setUndecorated(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(new Dimension(1080, 720));

        //Move window
        WindowMover mover = new WindowMover(this);
        this.addMouseListener(mover);
        this.addMouseMotionListener(mover);

        Object[][] data = {
                  {"Cysboy", new JButton("6boy"), new Double(1.80), new Boolean(true)},
                  {"BZHHydde", new JButton("BZH"), new Double(1.78), new Boolean(false)},
                  {"IamBow", new JButton("BoW"), new Double(1.90), new Boolean(false)},
                  {"FunMan", new JButton("Year"), new Double(1.85), new Boolean(true)}
                };
        String  title[] = {"Pseudo", "Age", "Taille", "OK ?"};

        STable table = new STable(500, 500);
        table.setTitle(title);
        table.setData(data);
        this.getContentPane().add(table.createTable());

        this.exitB = new SButton(this, "exitM", 1060, 8, true);
        this.hideB = new SButton(this, "hideM", 1037, 16, true);
        this.homeB = new SButton(this, "home", 9, 39, true);
        this.userB = new SButton(this, "user", 7, 610, true);
        this.settingB = new SButton(this, "settings", 7, 670, true);

        this.setVisible(true);
        this.setLocationRelativeTo(null);
        //Animator.fadeInFrame(this, Animator.FAST);
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource().equals(exitB))
            System.exit(0);
        else if(e.getSource().equals(hideB))
            this.setState(JFrame.ICONIFIED);
        else if(e.getSource().equals(homeB))
            return;
        else if(e.getSource().equals(settingB))
            return;
        else if(e.getSource().equals(userB))
            return;
    }
}
如果你有问题,请毫不犹豫地提出。对不起,有任何错误。 真诚地
Maki

请发布一个可以编译运行的代码:您正在使用我们一无所知的各种自定义组件。首先,尝试使用默认的JDK类使代码正常工作。如果这样做有效,那么问题在于您的自定义组件。如果它不起作用,那么你可以在论坛上发布一个MCVE。不,我的个人合作伙伴它只是扩展主类(SButton->extendsjbutton)。没有其他修改。我已经测试过了。