如何在Java应用程序的底部创建一个条形图,如状态栏? [英] How can I create a bar in the bottom of a Java app, like a status bar?

查看:124
本文介绍了如何在Java应用程序的底部创建一个条形图,如状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Java应用程序,并希望在应用程序的底部有一个
栏,我在其中显示一个文本栏和一个状态(进度)栏。

I am in the process of creating a Java app and would like to have a bar on the bottom of the app, in which I display a text bar and a status (progress) bar.

我似乎无法在NetBeans中找到控件,也不知道要手动创建的代码。

Only I can't seem to find the control in NetBeans neither do I know the code to create in manually.

推荐答案

使用BorderLayout创建一个JFrame或JPanel,给它类似 BevelBorder 或行边框,以便与其余内容分开,然后在BorderLayout.SOUTH添加状态面板。

Create a JFrame or JPanel with a BorderLayout, give it something like a BevelBorder or line border so it is seperated off from the rest of the content and then add the status panel at BorderLayout.SOUTH.

JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(200, 200);

// create the status bar panel and shove it down the bottom of the frame
JPanel statusPanel = new JPanel();
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
frame.add(statusPanel, BorderLayout.SOUTH);
statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
JLabel statusLabel = new JLabel("status");
statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
statusPanel.add(statusLabel);

frame.setVisible(true);

以下是我机器上的状态条形码的结果:

Here is the result of the above status bar code on my machine:

这篇关于如何在Java应用程序的底部创建一个条形图,如状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆