JAVA-使用Box.createGlue()将对象定位在屏幕底部?
我在互联网上的任何地方都找不到答案,所以我就在这里 带背景的JFrame 这就是我目前拥有的,上面写着“德克萨斯州凯蒂五旬节信徒”的标志是我正在研究的,也是版权标志 我希望标志在底部,版权在右下角。以下是构建框架的所有代码:JAVA-使用Box.createGlue()将对象定位在屏幕底部?,java,swing,Java,Swing,我在互联网上的任何地方都找不到答案,所以我就在这里 带背景的JFrame 这就是我目前拥有的,上面写着“德克萨斯州凯蒂五旬节信徒”的标志是我正在研究的,也是版权标志 我希望标志在底部,版权在右下角。以下是构建框架的所有代码: //Made by Trey Carey | 6.24.18 import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; impor
//Made by Trey Carey | 6.24.18
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class loginScreen {
static String versionNumber = new String("1.0"); //Version Number
static String applicationName = new String("Lower Thirds SDV " + versionNumber); //Application Name
public static void main(String[] args) throws IOException {
createLoginWindow();
}
public static void createLoginWindow() throws IOException {
JFrame mainFrame = new JFrame(applicationName);
//Images
BufferedImage loginImage = ImageIO.read(new File ("src/Lower Thirds SDV PNG Elements/Login_BTN.png"));
JLabel backgroundImage = new JLabel(new ImageIcon("src/Lower Thirds SDV PNG Elements/Main_BKG.png"));
JLabel logo = new JLabel(new ImageIcon("src/Lower Thirds SDV PNG Elements/POK Logo.png"));
JLabel copyrightImage = new JLabel(new ImageIcon("src/Lower Thirds SDV PNG Elements/Copyright.png"));
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
mainFrame.add(backgroundImage);
backgroundImage.setLayout(gridBagLayout);
//Create Login Button
JButton loginButton = new JButton(new ImageIcon (loginImage));
loginButton.setBorder(BorderFactory.createEmptyBorder());
c.anchor = GridBagConstraints.CENTER;
c.gridy = 0;
backgroundImage.add(loginButton, c);
c.gridy ++;
backgroundImage.add(copyrightImage, c);
backgroundImage.add(Box.createGlue(), c);
c.anchor = GridBagConstraints.PAGE_END;
c.gridy ++;
backgroundImage.add(logo, c);
mainFrame.setResizable(false);
mainFrame.setLocationRelativeTo(null);
mainFrame.pack();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
}
任何帮助都将不胜感激!谢谢大家!
使用Box.createGlue()将对象定位在屏幕底部
然后您需要使用BoxLayout
。阅读上Swing教程中的部分,以获取入门示例
<>你的组件在中间的原因是因为你在使用GRIDBAG布局,除非你指定WebXY/Y,否则组件将居中。有关这些约束的详细信息,请阅读上的教程
注意,您永远不会被迫使用单个布局管理器。因此,主面板可能使用BoxLayout。然后使用适当的布局管理器创建另外两个面板。然后您可以使用Box.createGlue()将底部面板与顶部面板分开。我在某个地方读到(在工作时找不到源代码),我也可以在GridBagLayout中使用此createGlue()。如果不可能,我该如何在那里添加空白?
如果不可能,我该如何在那里添加空白?
-按照我上面的建议使用嵌套面板。我在互联网上搜索到任何地方都没有找到答案
-我觉得很难相信。您只需使用“Box.createGlue()”作为关键字搜索论坛/网站。