首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将JPanel与JFrame(Java Swing)的底部对齐?

如何将JPanel与JFrame(Java Swing)的底部对齐?
EN

Stack Overflow用户
提问于 2018-08-14 06:23:11
回答 1查看 0关注 0票数 0

我正在制作一个简单的Java音频播放器,并开始使用GUI; 没有事件,也没有任何功能。我问我如何使用按钮(控件)将JPanel对齐到主窗口的底部中心(JFrame)。

这是代码:

代码语言:javascript
复制
import javax.swing.*;
import java.awt.*;
public class tryingtowindow extends JFrame {

  //Buttons
public JButton rewind;
 public JButton play;
  public JButton fastForward;

  //the window
public JFrame UI;
public JPanel controls;

//main gui function
public tryingtowindow(){

//rewind button
rewind = new JButton(new ImageIcon ("rewind.png"));
rewind.setBackground(Color.WHITE);
rewind.setFocusPainted(false);

//playbutton
play = new JButton(new ImageIcon ("play.png"));
play.setBackground(Color.WHITE);
play.setFocusPainted(false);

//fastforward button
fastForward = new JButton(new ImageIcon ("fastforward.png"));
fastForward.setBackground(Color.WHITE);
fastForward.setFocusPainted(false);

//panel w/buttons
controls = new JPanel();
controls.add(rewind);
controls.add(play);
controls.add(fastForward);
controls.setBackground(Color.BLACK);

//window
UI = new JFrame();
UI.setLayout(new FlowLayout(FlowLayout.CENTER));
UI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
UI.setSize(400, 140);
UI.setVisible(true);
UI.setResizable(false);
UI.setTitle("title");
UI.add(controls);

 }

public static void main(String args[]) {

new tryingtowindow();

  }
}
EN

回答 1

Stack Overflow用户

发布于 2018-08-14 16:16:46

使用BorderLayout并将你的面板放入BorderLayout.SOUTH中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档