简体   繁体   English

在Java JFrame上添加图像-Netbeans

[英]Adding images on Java JFrame - Netbeans

I'm using NetBeans 7.1 to code in Java. 我正在使用NetBeans 7.1在Java中进行编码。 I have already created a JFrame filled with some labels, textbox and buttons . 我已经创建了一个JFrame ,其中填充了一些labels, textbox and buttons How can I do to import some image (JPG,PNG,etc...) from my PC into the same JFrame ? 如何将PC中的某些图像(JPG,PNG,etc...)导入同一JFrame On an specific location of the frame. 在框架的特定位置。

  1. Open the form in NetBeans form editor. 在NetBeans表单编辑器中打开表单。
  2. Add a JLabel from the pallete to the form JLabel从面板添加到表单
  3. Select the label you just added and click the "..." button next to the icon property 选择您刚刚添加的标签,然后单击icon属性旁边的“ ...”按钮
  4. Fill out the properties. 填写属性。

It's normally best that the images reside within the project folder, makes deployment easier in the long run. 通常最好将映像保存在项目文件夹中,从长远来看使部署更容易。

  1. Copy Image to your Netbeans project. 将图像复制到您的Netbeans项目。
  2. Add new label to the frame. 将新标签添加到框架。
  3. Select the label and Right click->Go to Properties. 选择标签,然后右键单击->转到属性。
  4. In Icon property select image by down arrow as shown in image. 在“图标”属性中,通过向下箭头选择图像,如图所示。

在此处输入图片说明

确保在添加JLabel时从Swing控件而不是AWT中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM