السلام عليكم ورحمة الله وبركاته
لدي كلاس من نوع JFrame
وداخله JPanel لرسم المكونات عليها
أريد وضع الخلفية صورة في واجهتي وجربت عدة طرق لكنها توقف عمل برنامج وبعضها لا يوقف العمل لكنه لا يغير أي شيء في الواجهه والبعض الأخير لم أستطع وضعه في كودي
من المشاركة للفاضل حسام :
/index.php?showtopic=66368&view=findpost&p=329259
قمت بعمل :
JPanel Panel = new JPanel(){
public void paint(Graphics g){
Image img = new ImageIcon("images/GetAttachment.aspx-(22).jpg").getImage();
g.drawImage(img, 700, 500,this);
super.paint(g); //to paint Components
}
};
Panel.setLayout(new GridBagLayout());
Panel.setMinimumSize(new Dimension(700, 500));
Panel.setPreferredSize(new Dimension(700, 500));لكنه لم يغير شيء في الواجهه
أيضًا جربت:
Image backgroundImagee=new ImageIcon(("images/GetAttachment.aspx-(22).jpg")).getImage();
Icon backgroundIcon=new Icon(backgroundImagee);
// create a label to paint the background image
JLabel backgroundImage = new JLabel(backgroundIcon);
// set minimum and preferred sizes so that the size of the image
// does not affect the layout size
backgroundImage.setPreferredSize(new Dimension(1,1));
backgroundImage.setMinimumSize(new Dimension(1,1));
// align the image as specified.
backgroundImage.setVerticalAlignment(700);
backgroundImage.setHorizontalAlignment(500);
GridBagConstraints gbc = new GridBagConstraints();
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.NORTHWEST;
// add the background label
Panel.add(backgroundImage, gbc);لكن هناك خطأ في وضعي للصورة داخل الآيكون ولم أعرف كيف أحلّه..
أي اقتراح بالنسبة للأكواد التي وضعتُ أو طريقة أسهل لوضع الصورة كخلفية؟

