0

GUI

I created this graphical interface, and what is missing is the "PERSONAL INFORMATION" border. I know that setBorder(BorderFactory.createTitledBorder("PERSONAL INFORMATION)) creates a border but how would I located the title to the Top Left, and input the correct dimensions so that the line doesn't go under the buttons without using layout managers. Much appreciated.

Michel Tamer
  • 341
  • 1
  • 3
  • 10
  • The title is top/left by default and the border insets are calculated automatically by the components `getPreferred/Miniumum/MaximumSize` method... – MadProgrammer Feb 20 '14 at 02:43
  • 1
    *"..without using layout managers."* That's where you lose me. Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Feb 20 '14 at 03:11
  • @AndrewThompson We are not allowed using any layout managers and we must layout each component manually by calculating location and size. I wish we were allowed, it would have made it much easier to do. – Michel Tamer Feb 20 '14 at 03:55
  • 1
    *"..without using layout managers."* I could show you how to lay it out like [this](http://i.stack.imgur.com/u4DeK.png).. Would that suit the requirement? – Andrew Thompson Feb 20 '14 at 04:32
  • 1
    *"We are not allowed using any layout managers"* That is so illogical, that if it were specified by a teacher, they should be flogged. If specified by an employer, find a new job. Even with a 'custom' layout manager, it is 'using a layout manager'. By the time you have laid out the components to fit the font size, screen resolution etc., you will have enough logic to justify **putting that logic** into a layout manager! – Andrew Thompson Feb 20 '14 at 04:35
  • @AndrewThompson I guess our Professor is trying to get us to understand the very basics of GUI – Michel Tamer Feb 20 '14 at 05:57

1 Answers1

4
    -

   import java.awt.*;
   import javax.swing.*;
   import javax.swing.border.*;

class BorderTest extends JFrame
 {
 public BorderTest()
 {
setTitle("Border Test");
setSize(450, 450);

JPanel content = (JPanel) getContentPane(); 
content.setLayout(new GridLayout(6,2));

JPanel p = new JPanel();
p.setBorder(new BevelBorder (BevelBorder.RAISED));
p.add(new JLabel("RAISED BevelBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new BevelBorder (BevelBorder.LOWERED));
p.add(new JLabel("LOWERED BevelBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new LineBorder (Color.black, 5));
p.add(new JLabel("Black LineBorder, thickness = 5"));
content.add(p);

p = new JPanel();
p.setBorder(new EmptyBorder (10,10,10,10));
p.add(new JLabel("EmptyBorder with thickness of 10"));
content.add(p);

p = new JPanel();
p.setBorder(new EtchedBorder (EtchedBorder.RAISED));
p.add(new JLabel("RAISED EtchedBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new EtchedBorder (EtchedBorder.LOWERED));
p.add(new JLabel("LOWERED EtchedBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new SoftBevelBorder (SoftBevelBorder.RAISED));
p.add(new JLabel("RAISED SoftBevelBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new SoftBevelBorder (SoftBevelBorder.LOWERED));
p.add(new JLabel("LOWERED SoftBevelBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new MatteBorder (new ImageIcon("spiral.gif")));
p.add(new JLabel("MatteBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new TitledBorder ( new MatteBorder (new ImageIcon("spiral.gif")), "Title String"));
p.add(new JLabel("TitledBorder using MatteBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new TitledBorder (new LineBorder (Color.black, 5), "Title String"));
p.add(new JLabel("TitledBorder using LineBorder"));
content.add(p);

p = new JPanel();
p.setBorder(new TitledBorder (
  new EmptyBorder (10,10,10,10),
  "Title String"));
p.add(new JLabel("TitledBorder using EmptyBorder"));
content.add(p);

setVisible(true);
 }

public static void main(String args[])
{
new BorderTest();
}
}
  1. This Demo example is shows all Type of border.i think so it is helpfull for you.

enter image description here

Benjamin
  • 2,257
  • 1
  • 15
  • 24