473,327 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Wrong display of JComponents (Java)

Hello,

Java: 1.6.0_23
Netbeans: 6.9.1

I`m making chatting program and I wanted to add a background image to the main window. So I added a image via JPanel and after that the components are no longer displaying properly. The components are displayed after i point/click on them with the mouse, except the JLabel components. On the attached screenshots you can see what is the problem and the difference. Here is the code of the window:

Expand|Select|Wrap|Line Numbers
  1. public Login() {
  2.         BufferedImage icon = null;
  3.         URL path = null;
  4.  
  5.         language.Init(); // The applications is multilangual, so initializes the language
  6.         this.setTitle(language.getMessage("LOGIN_WINDOW_TITLE")); 
  7.  
  8.         path = getClass().getResource("images/securChatter_01.jpg");
  9.         JPanel panel = new WindowBackground(new ImageIcon(path).getImage());
  10.  
  11.         panel.setLayout(new GridBagLayout());
  12.         GridBagConstraints gbCons = new GridBagConstraints();
  13.  
  14.         //adding the components
  15.         gbCons.gridx = 0;
  16.         gbCons.gridy = 0;
  17.         lblUserName = new JLabel(language.getMessage("USERNAME"));
  18.         panel.add(lblUserName, gbCons);
  19.  
  20.         gbCons.gridx = 0;
  21.         gbCons.gridy = 1;
  22.         txtUsrName = new JTextField(10);
  23.         panel.add(txtUsrName, gbCons);
  24.  
  25.         gbCons.gridx = 0;
  26.         gbCons.gridy = 2;
  27.         lblUserPwd = new JLabel(language.getMessage("PASSWORD"));
  28.         panel.add(lblUserPwd, gbCons);
  29.  
  30.         gbCons.gridx = 0;
  31.         gbCons.gridy = 3;
  32.         txtUsrPwd = new JPasswordField(10);
  33.         panel.add(txtUsrPwd, gbCons);
  34.  
  35.         JPanel btnPanel = new JPanel();
  36.         btnPanel.setLayout(new FlowLayout());
  37.  
  38.         icon = loadIcon(labelIcon, "loginIcon.png");
  39.  
  40.         lblLoginIcon = new JLabel(new ImageIcon(icon));
  41.         lblLoginIcon.setToolTipText(language.getMessage("LOGIN_BUTTON"));
  42.         lblLoginIcon.addMouseListener(this);
  43.         btnPanel.add(lblLoginIcon);
  44.  
  45.         icon = loadIcon(labelIcon, "registerIcon.png");
  46.  
  47.         lblRegisterIcon = new JLabel(new ImageIcon(icon));
  48.         lblRegisterIcon.setToolTipText(language.getMessage("REGISTER_BUTTON"));
  49.         lblRegisterIcon.addMouseListener(this);
  50.         btnPanel.add(lblRegisterIcon);
  51.  
  52.         icon = loadIcon(labelIcon, "settingsIcon.png");
  53.  
  54.         lblSettingsIcon = new JLabel(new ImageIcon(icon));
  55.         lblSettingsIcon.setToolTipText(language.getMessage("SETTINGS_BUTTON"));
  56.         lblSettingsIcon.addMouseListener(this);
  57.         btnPanel.add(lblSettingsIcon);
  58.  
  59.         gbCons.gridx = 0;
  60.         gbCons.gridy = 4;
  61.         gbCons.anchor = GridBagConstraints.CENTER;
  62.         gbCons.gridwidth = 2;
  63.         panel.add(btnPanel, gbCons);
  64.  
  65.         getContentPane().add(panel);
  66.         setSize(150, 180);
  67.         setLocationRelativeTo(null);
  68.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  69.         setVisible(true);
  70.     }
Here is the code of WindowBackground:

Expand|Select|Wrap|Line Numbers
  1. public class WindowBackground extends JPanel {
  2.  
  3.     // The Image to store the background image in.
  4.     Image img;
  5.  
  6.     public WindowBackground(Image img) {
  7.         this.img = img;
  8.     }
  9.  
  10.     public void paint(Graphics g) {
  11.         // Draws the img to the BackgroundPanel.
  12.         g.drawImage(img, 0, 0, null);
  13.     }
  14. }
Attached Images
File Type: jpg withBackgroundImage.jpg (8.1 KB, 100 views)
File Type: jpg withoutBackgroundImage.jpg (6.1 KB, 95 views)
Dec 28 '10 #1
0 1326

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
0
by: Frlo | last post by:
Hi, I have problem that I tried to solve but i missed out. My situation: I have problem that my page www.vodotika.sk display some wrong characters. Apache server 2.0.54 runs on windows-1250...
5
by: Zach | last post by:
This is all on linux using jdk1.3. My application is written in AWT, no swing. The application requires running it on the host machine and tunneling the GUI back to a client. I've been doing...
4
by: Abram Friesen | last post by:
Hi all, I'm a newbie at DB2 and trying to create a simple java UDF. When I call my function, I'm receiving SQL4306N. Could someone please tell me what I'm doing wrong here? Here is my java...
3
by: SJM | last post by:
I have a problem that occurs occasionally with a db for a undetermined reason which I would love to solve. I construct and append a series of 7 records to a table using ADO recordset. Each record...
2
by: Paul | last post by:
Hi I have some code and java script, when the page initially loads I want it to have focus on dr_tx_names. This works. The page loads a second time with a dropdown selection and in the code...
3
by: nkechifesie | last post by:
I want my form to display the absolute position and the recordcount of the records in the database but it keeps shoing me -1 for both . Why? this is the code Private Sub MnuOVehType_Click()...
9
by: TomC | last post by:
Is there any resource where someone who is familiar with Java might find which .NET classes are similar to classes they are familiar with in Java? For example, I have a project that I'd like to...
3
by: rajarya | last post by:
Hi, I m designing a HTML page(index.html),here i have 2 frames,by defult both frames have index1.html and index2.html as their source . in first frame(index.html) ,i have some redio buttons,and a...
4
by: phpuser123 | last post by:
I just happened to read abt vectors in java..For some practice,I implemented this small script where I Store objects in a vector..Then,I want to invoke the methods of the corresponding objects.My...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.