0

I have a JPanel with a TitledBorder called 'panelLogin' with white background on top of another JPanel colored blue.

Is there a way for the 'panelLogin' to lose the white edges outside of the TitledBorder to make it look nicer? I was hoping to get the TitledBorder look of the panel but without the excess white space outside.

    JPanel panelBackground = new JPanel();
    panelBackground.setBackground(new Color(70, 130, 180));
    panelBackground.setBounds(0, 0, 316, 302);
    panelBackground.setLayout(null);

    JPanel panelLogin = new JPanel();
    panelLogin.setBorder(new TitledBorder(null, "Login", TitledBorder.LEADING, TitledBorder.TOP, 
            new Font("Segoe UI", Font.BOLD, 14), null));
    panelLogin.setBackground(Color.WHITE);
    panelLogin.setBounds(10, 118, 296, 172);
    panelBackground.add(panel_1);

Thanks in advance. I don't have enough rep yet to post an image so I could show. Sorry.

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
mfrancisp
  • 119
  • 1
  • 1
  • 10
  • 2
    Just a quick tip for posting an image if you can't post the link to the image :). And it looks like I am missing some code because you variable panel_1 does not exists. – Roan Aug 11 '14 at 19:22
  • Swing GUIs might have to work on different platforms, using different PLAFs, on different screen sizes and resolutions with different default settings for font size. As such, they are not conducive to exact placement of components. Instead use layout managers, or [combinations of layout managers](http://stackoverflow.com/a/5630271/418556) as well as [layout padding and borders](http://stackoverflow.com/q/17874717/418556) for white space. – Andrew Thompson Aug 12 '14 at 01:21
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal, Complete, Verifiable Example). – Andrew Thompson Aug 12 '14 at 01:22

0 Answers0