如何将JLabel放在标题栏正下方的右上角? [英] How to place JLabel on top right corner just below the title bar?

查看:364
本文介绍了如何将JLabel放在标题栏正下方的右上角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我读过关于Layouts但是没有得到哪一个用于我的应用程序。
我想将图像添加到JPanel并将JLabel放在标题栏正下方的右上角。

Hello I read about Layouts but didn't get which one to use for my application. I want to add image to JPanel and place JLabel on op right corner just below the title bar.

我已为此编写代码,但它无效。 JLabel显示在中心。

I have written code for that but it is not working. JLabel is displayed at Centre.

我的代码是

// Below line adds image to Jpanel
 panel = new ImagePanel(backgroundImage);
 // I want to add below label to Jpanel
 JLabel jdesignNo=new JLabel(designNo);
 jdesignNo.setFont((new java.awt.Font("Times New Roman", 1, 30)));
 jdesignNo.setBounds(900, 100, 50, 30);
 jdesignNo.setBackground(Color.GREEN);
 panel.add(jdesignNo);
 frame.getContentPane().add(panel);
 frame.setVisible(true);

在上面的代码中,我已经通过setBound设置了所需的位置,但它不起作用。

In above code i have set required location by setBound but it does not work.

如何解决这个问题?

谢谢!!!

推荐答案

确保你有

panel.setLayout(null);

如果您想自己定位组件。

if you wish to position the components yourself.

但是,随着应用程序复杂性的增加,识别和使用适合您需求的布局管理器会使事情变得更容易。

But identifying and using a layout manager that would fit your needs would make things easier as the complexity of your application grows.

这篇关于如何将JLabel放在标题栏正下方的右上角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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