java jpanel对齐,如何将JPanel与JFrame的底部对齐(java swing)

Long story short, I'm making a simple audio player in Java and am starting the GUI; no events, no functionality of any kind as of yet.

I'm asking how I can the JPanel with the buttons (controls), to align to the bottom center of the main window (JFrame).

Here's the code.

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();

}

}

The FlowLayout() in JFrame covers the center alignment; so what covers the bottom?

解决方案

Use BorderLayout and put your panel in the BorderLayout.SOUTH of it

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值