Border not rendering properly on JPanel

This is just a general question to see if I'm the only one having this problem or whether it is just a bug.

I've got a Jframe with a couple of Jpanels within it. I want a border round one of the panels but for some reason the border only shows fully around 3 edges and only partly along the edge adjacent to the other JPanel.

I thought this might be a layering problem with the panel without the border being placed on top of the border itself but I've had a similar problem with some JTextField. I've got 3 JTextFields in a JPanel each having their own border but every now and again the border will disappear from around the bottom JTextField.

I realise this may well be a problem specific to my system or OS (Win 2000) but I thought I'd just check.

Thanks, Clarkie

[807 byte] By [clarkie99a] at [2007-10-3 2:51:39]
# 1

> I realise this may well be a problem specific to my system or OS (Win 2000) but I thought I'd just check.

Well then post executable DEMO code so we can test it out and verrify whether we experience the same problem. I've never noticed problems and I have no idea what your code looks like.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-14 20:40:33 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks for replying so quickly. Here is a cut down version of my code. I appologise now for using NetBeans as I believe this is frowned upon by many users of these forums.

/*

* NewJFrame.java

*

* Created on 14 August 2006, 15:17

*/

package ets;

import java.awt.*;

import javax.swing.*;

/**

*

* @author administrator

*/

public class sscce extends javax.swing.JFrame

{

/** Creates new form NewJFrame */

public sscce()

{

initComponents();

this.setIconImage(new ImageIcon("images/redtick48x48.gif").getImage());

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

private void initComponents()

{

java.awt.GridBagConstraints gridBagConstraints;

panelCont = new javax.swing.JPanel();

panelNav = new javax.swing.JPanel();

panelBtnsAndImg = new javax.swing.JPanel();

panelNavBtns = new javax.swing.JPanel();

btnNav_client = new javax.swing.JButton();

btnNav_job = new javax.swing.JButton();

btnNav_inv = new javax.swing.JButton();

btnNav_cert = new javax.swing.JButton();

btnNav_admin = new javax.swing.JButton();

panelLogout = new javax.swing.JPanel();

panelMain = new javax.swing.JPanel();

panelClientMenu = new javax.swing.JPanel();

panelClientMent_title = new javax.swing.JPanel();

labClientMent_title = new javax.swing.JLabel();

jMenuBar1 = new javax.swing.JMenuBar();

jMenu1 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("ETS - Client Management System");

setBackground(new java.awt.Color(255, 255, 255));

setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);

setName("mainFrame");

panelCont.setLayout(new java.awt.BorderLayout());

panelCont.setBackground(new java.awt.Color(255, 255, 255));

panelNav.setLayout(new java.awt.BorderLayout());

panelNav.setBackground(new java.awt.Color(255, 255, 255));

panelNav.setMaximumSize(new java.awt.Dimension(150, 150));

panelNav.setPreferredSize(new java.awt.Dimension(150, 100));

panelBtnsAndImg.setLayout(new java.awt.GridLayout(0, 1));

panelBtnsAndImg.setBackground(new java.awt.Color(255, 255, 255));

panelBtnsAndImg.setMaximumSize(new java.awt.Dimension(150, 32767));

panelNavBtns.setLayout(new java.awt.GridLayout(0, 1));

panelNavBtns.setBackground(new java.awt.Color(255, 255, 255));

btnNav_client.setText("Clients");

panelNavBtns.add(btnNav_client);

btnNav_job.setText("Jobs");

panelNavBtns.add(btnNav_job);

btnNav_inv.setText("Invoices");

panelNavBtns.add(btnNav_inv);

btnNav_cert.setText("Certificates");

panelNavBtns.add(btnNav_cert);

btnNav_admin.setText("Admin");

panelNavBtns.add(btnNav_admin);

panelBtnsAndImg.add(panelNavBtns);

panelNav.add(panelBtnsAndImg, java.awt.BorderLayout.NORTH);

panelLogout.setLayout(new java.awt.BorderLayout());

panelLogout.setBackground(new java.awt.Color(255, 255, 255));

panelLogout.setMaximumSize(new java.awt.Dimension(150, 32767));

panelNav.add(panelLogout, java.awt.BorderLayout.CENTER);

panelCont.add(panelNav, java.awt.BorderLayout.WEST);

panelMain.setLayout(new java.awt.CardLayout());

panelMain.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

panelClientMenu.setLayout(new java.awt.GridBagLayout());

panelClientMenu.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

panelClientMent_title.setLayout(new java.awt.BorderLayout());

labClientMent_title.setFont(new java.awt.Font("Tahoma", 0, 36));

labClientMent_title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

labClientMent_title.setText("Main Panel");

panelClientMent_title.add(labClientMent_title, java.awt.BorderLayout.CENTER);

gridBagConstraints = new java.awt.GridBagConstraints();

gridBagConstraints.ipadx = 5;

gridBagConstraints.ipady = 15;

panelClientMenu.add(panelClientMent_title, gridBagConstraints);

panelMain.add(panelClientMenu, "card2");

panelCont.add(panelMain, java.awt.BorderLayout.CENTER);

getContentPane().add(panelCont, java.awt.BorderLayout.CENTER);

jMenu1.setText("Menu");

jMenuBar1.add(jMenu1);

setJMenuBar(jMenuBar1);

pack();

}// </editor-fold>

/**

* @param args the command line arguments

*/

public static void main(String args[])

{

Toolkit tk = java.awt.Toolkit.getDefaultToolkit();

java.awt.EventQueue.invokeLater(new Runnable()

{

public void run()

{

sscce s = new sscce();

s.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);

s.setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton btnNav_admin;

private javax.swing.JButton btnNav_cert;

private javax.swing.JButton btnNav_client;

private javax.swing.JButton btnNav_inv;

private javax.swing.JButton btnNav_job;

private javax.swing.JMenu jMenu1;

private javax.swing.JMenuBar jMenuBar1;

private javax.swing.JLabel labClientMent_title;

private javax.swing.JPanel panelBtnsAndImg;

private javax.swing.JPanel panelClientMent_title;

private javax.swing.JPanel panelClientMenu;

private javax.swing.JPanel panelCont;

private javax.swing.JPanel panelLogout;

private javax.swing.JPanel panelMain;

private javax.swing.JPanel panelNav;

private javax.swing.JPanel panelNavBtns;

// End of variables declaration

}

Also, I sometimes get a diagonal line going from the top left corner of a container to the first element when the JFrame is resized or reloaded from the Taskbar.

Thanks again, Clarkie

clarkie99a at 2007-7-14 20:40:33 > top of Java-index,Desktop,Core GUI APIs...
# 3

Works fine for me using JDK1.4.2 on XP. I changed the border color to something other than black so I could distinguish the border from the monitor background. Since I still use a CRT monittor the right border was hard to distinguish from the monitor background buy it definitely was there.

Didn't notice any problems with a diagonal line either.

camickra at 2007-7-14 20:40:33 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks for taking the time to have a look. I haven't got a clue what's going on on my machine then. I've actually noticed netbeans showing some random diagonal lines in the project view when expanding and collapsing the tree.
clarkie99a at 2007-7-14 20:40:33 > top of Java-index,Desktop,Core GUI APIs...
# 5
I just thought I'd give you and update. Its all sorted. It was a problem with my graphics card and nothing to do with Java! Thanks for taking the time anyway.Clarkie
clarkie99a at 2007-7-14 20:40:33 > top of Java-index,Desktop,Core GUI APIs...