Java swing 用托控件的方式做的界面,不是打代码那种,如何添加背景图片
1个回答
展开全部
我也是用windowBuilder做的,之前回答其他问题写过一个例子,你可以看下
http://zhidao.baidu.com/question/875861115528159092.html?from=pubpage&msgtype=2
package my.test.main;
import java.awt.BorderLayout;
public class First extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
First dialog = new First();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public First() {
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setLayout(new GridLayout(1, 1));
getContentPane().add(contentPanel, BorderLayout.CENTER);
JLabel bgLb = new JLabel();
bgLb.setIcon(new ImageIcon("bg.jpg"));
bgLb.setHorizontalAlignment(SwingConstants.CENTER);
contentPanel.add(bgLb);
bgLb.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 50));
textField = new JTextField();
bgLb.add(textField);
textField.setColumns(10);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询