将JFrame移到frame.setLocationRelativeobutton之后的左侧

问题描述

这可能是一个愚蠢的问题,但是我在网上找不到任何东西。我只想创建一个JFrame并将其放在按钮旁边。但是,当我相对于按钮设置它时,它将其设置在按钮的中间而不是左侧,因此两个组件的中心重叠。

我认为该代码不需要任何代码,但无论如何我都会给您

public void RezeptnachnameB() {
    JFrame frame = new JFrame("Rezept nach Name");
    frame.getContentPane().setLayout(new GridLayout(2,1));
    KnopfRNN = new JButton("Suche");
    KnopfRNN.addActionListener(this);
    TextBox = new JTextField();
    label2 = new JLabel("Welches Rezept suchen Sie?");
    label2.setSize(500,300);
    Rectangle r= frame.getBounds();
    h=r.height/2;
    w=r.width/2;
    int he=250;
    int wi=750;
    w-=wi/2;        
    KnopfRNN.setFont(font);
    TextBox.setFont(font);
    TextBox.setSize(500,300);
    label2.setFont(font);
    KnopfRNN.setSize(1000,300);


    TextBox.requestFocus();
    frame.getContentPane().add(label2);
    frame.getContentPane().add(TextBox);
    frame.getContentPane().add(KnopfRNN);

    frame.setLocationRelativeto(MainRNN);
    
    frame.pack();
    frame.setVisible(true);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)