List of usage examples for javax.swing.border TitledBorder TitledBorder
public TitledBorder(Border border, String title)
From source file:ATitledBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border thisBorder = BorderFactory.createTitledBorder("Easy"); Border thatBorder1 = new LineBorder(Color.RED); Border thatBorder2 = new TitledBorder(thatBorder1, "Harder"); Font font = new Font("Serif", Font.ITALIC, 12); Border thatBorder = new TitledBorder(thatBorder2, "Harder", TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM, font, Color.RED);/*from ww w. j a v a2 s . com*/ JButton thisButton = new JButton("Easy"); thisButton.setBorder(thisBorder); JButton thatButton = new JButton("Harder"); thatButton.setBorder(thatBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2)); contentPane.add(thisButton); contentPane.add(thatButton); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setTitle("Example2"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p1.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 1")); for (int i = 0; i < NB1; i++) p1.add(new JButton("Button " + i)); JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p2.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 2")); for (int i = NB1; i < NB2; i++) p2.add(new JButton("Button " + i)); JPanel p3 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p3.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 3")); for (int i = NB2; i < NB3; i++) p3.add(new JButton("Button " + i)); JPanel global = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; // added gbc.weightx = 1.0f; // added gbc.gridy = 0;/*www . j av a2 s .com*/ global.add(p1, gbc); gbc.gridy++; global.add(p2, gbc); gbc.gridy++; global.add(p3, gbc); f.add(global); f.pack(); f.setVisible(true); }
From source file:ATitledBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border thisBorder = BorderFactory.createTitledBorder("Easy"); Icon thatIcon = new ImageIcon("diamond.gif"); Border thatBorder1 = new MatteBorder(18, 20, 18, 20, thatIcon); Border thatBorder2 = new TitledBorder(thatBorder1, "Harder"); Font font = new Font("Serif", Font.ITALIC, 12); Border thatBorder = new TitledBorder(thatBorder2, "Harder", TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM, font, Color.red);//from www . j a v a2 s.co m JButton thisButton = new JButton("Easy"); thisButton.setBorder(thisBorder); JButton thatButton = new JButton("Harder"); thatButton.setBorder(thatBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2)); contentPane.add(thisButton); contentPane.add(thatButton); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Titled Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border thisBorder = BorderFactory.createTitledBorder("Easy"); Icon thatIcon = MetalIconFactory.getFileChooserHomeFolderIcon(); Border thatBorder1 = new MatteBorder(18, 20, 18, 20, thatIcon); Border thatBorder2 = new TitledBorder(thatBorder1, "Harder"); Font font = new Font("Serif", Font.ITALIC, 12); Border thatBorder = new TitledBorder(thatBorder2, "Hardest", TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM, font, Color.RED);/*from w w w .j a v a2 s . c om*/ JButton thisButton = new JButton("Easy"); thisButton.setBorder(thisBorder); JButton thatButton = new JButton("Harder"); thatButton.setBorder(thatBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2)); contentPane.add(thisButton); contentPane.add(thatButton); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame aWindow = new JFrame("This is a Box Layout"); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box left = Box.createVerticalBox(); left.add(Box.createVerticalStrut(30)); ButtonGroup radioGroup = new ButtonGroup(); JRadioButton rbutton;//from ww w. j a v a 2 s . c om radioGroup.add(rbutton = new JRadioButton("Red")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Green")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Blue")); left.add(rbutton); left.add(Box.createVerticalStrut(30)); radioGroup.add(rbutton = new JRadioButton("Yellow")); left.add(rbutton); left.add(Box.createGlue()); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Color")); leftPanel.add(left, BorderLayout.CENTER); Box right = Box.createVerticalBox(); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Dashed")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Thick")); right.add(Box.createVerticalStrut(30)); right.add(new JCheckBox("Rounded")); right.add(Box.createGlue()); JPanel rightPanel = new JPanel(new BorderLayout()); rightPanel.setBorder(new TitledBorder(new EtchedBorder(), "Line Properties")); rightPanel.add(right, BorderLayout.CENTER); Box top = Box.createHorizontalBox(); top.add(leftPanel); top.add(Box.createHorizontalStrut(5)); top.add(rightPanel); Container content = aWindow.getContentPane(); content.setLayout(new BorderLayout()); content.add(top, BorderLayout.CENTER); BoxLayout box = new BoxLayout(content, BoxLayout.Y_AXIS); content.setLayout(box); content.add(top); aWindow.setVisible(true); }
From source file:Main.java
public Main() { JCheckBox m_chkBold = new JCheckBox("Bold"); m_chkBold.setMnemonic('b'); m_chkBold.setToolTipText("Bold font"); add(m_chkBold);/*from w w w . j a v a 2s . c o m*/ setBorder(new TitledBorder(new EtchedBorder(), "Effects")); JCheckBox m_chkItalic = new JCheckBox("Italic"); m_chkItalic.setMnemonic('i'); m_chkItalic.setToolTipText("Italic font"); add(m_chkItalic); JCheckBox m_chkUnderline = new JCheckBox("Underline"); m_chkUnderline.setMnemonic('u'); m_chkUnderline.setToolTipText("Underline font"); add(m_chkUnderline); JCheckBox m_chkStrikethrough = new JCheckBox("Strikethrough"); m_chkStrikethrough.setMnemonic('r'); m_chkStrikethrough.setToolTipText("Strikethrough font"); add(m_chkStrikethrough); JCheckBox m_chkSubscript = new JCheckBox("Subscript"); m_chkSubscript.setMnemonic('t'); m_chkSubscript.setToolTipText("Subscript font"); add(m_chkSubscript); JCheckBox m_chkSuperscript = new JCheckBox("Superscript"); m_chkSuperscript.setMnemonic('p'); m_chkSuperscript.setToolTipText("Superscript font"); add(m_chkSuperscript); }
From source file:CheckBoxMnemonic.java
public CheckBoxMnemonic() { JCheckBox m_chkBold = new JCheckBox("Bold"); m_chkBold.setMnemonic('b'); m_chkBold.setToolTipText("Bold font"); add(m_chkBold);//from w w w . ja v a 2 s . c om setBorder(new TitledBorder(new EtchedBorder(), "Effects")); JCheckBox m_chkItalic = new JCheckBox("Italic"); m_chkItalic.setMnemonic('i'); m_chkItalic.setToolTipText("Italic font"); add(m_chkItalic); JCheckBox m_chkUnderline = new JCheckBox("Underline"); m_chkUnderline.setMnemonic('u'); m_chkUnderline.setToolTipText("Underline font"); add(m_chkUnderline); JCheckBox m_chkStrikethrough = new JCheckBox("Strikethrough"); m_chkStrikethrough.setMnemonic('r'); m_chkStrikethrough.setToolTipText("Strikethrough font"); add(m_chkStrikethrough); JCheckBox m_chkSubscript = new JCheckBox("Subscript"); m_chkSubscript.setMnemonic('t'); m_chkSubscript.setToolTipText("Subscript font"); add(m_chkSubscript); JCheckBox m_chkSuperscript = new JCheckBox("Superscript"); m_chkSuperscript.setMnemonic('p'); m_chkSuperscript.setToolTipText("Superscript font"); add(m_chkSuperscript); }
From source file:Main.java
public Main() { setSize(500, 340);/*from ww w. ja v a 2 s .c om*/ Date currentDate = new Date(); calendar.setTime(currentDate); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(4, 1)); JPanel p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Selected Date")); dateLabel = new JLabel(dateFormat.format(currentDate) + " "); dateLabel.setFont(new Font("Arial", Font.BOLD, 24)); p.add(dateLabel); p1.add(p); yearSlider.setPaintLabels(true); yearSlider.setMajorTickSpacing(5); yearSlider.setMinorTickSpacing(1); yearSlider.setPaintTicks(true); DateListener lst = new DateListener(); yearSlider.addChangeListener(lst); p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Year")); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(Box.createRigidArea(RIGID_DIMENSION)); p.add(yearSlider); p.add(Box.createRigidArea(RIGID_DIMENSION)); p1.add(p); String[] months = (new DateFormatSymbols()).getShortMonths(); hashTable = new Hashtable(12); for (int i = 0; i < 12; i++) hashTable.put(new Integer(i + 1), new JLabel(months[i], JLabel.CENTER)); monthSlider.setLabelTable(hashTable); monthSlider.setPaintLabels(true); monthSlider.setMajorTickSpacing(1); monthSlider.setPaintTicks(true); monthSlider.addChangeListener(lst); p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Month")); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(Box.createRigidArea(RIGID_DIMENSION)); p.add(monthSlider); p.add(Box.createRigidArea(RIGID_DIMENSION)); p1.add(p); int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); daySlider = new JSlider(JSlider.HORIZONTAL, 1, maxDays, calendar.get(Calendar.DAY_OF_MONTH)); daySlider.setPaintLabels(true); daySlider.setMajorTickSpacing(5); daySlider.setMinorTickSpacing(1); daySlider.setPaintTicks(true); daySlider.addChangeListener(lst); p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Day")); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(Box.createRigidArea(RIGID_DIMENSION)); p.add(daySlider); p.add(Box.createRigidArea(RIGID_DIMENSION)); p1.add(p); getContentPane().add(p1, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); enableEvents(ComponentEvent.COMPONENT_RESIZED); setVisible(true); }
From source file:BoxLayoutPane.java
public BoxLayoutPane() { // Use a BorderLayout layout manager to arrange various Box components this.setLayout(new BorderLayout()); // Give the entire panel a margin by adding an empty border // We could also do this by overriding getInsets() this.setBorder(new EmptyBorder(10, 10, 10, 10)); // Add a plain row of buttons along the top of the pane Box row = Box.createHorizontalBox(); for (int i = 0; i < 4; i++) { JButton b = new JButton("B" + i); b.setFont(new Font("serif", Font.BOLD, 12 + i * 2)); row.add(b);// w ww. j a v a 2 s. c om } this.add(row, BorderLayout.NORTH); // Add a plain column of buttons along the right edge // Use BoxLayout with a different kind of Swing container // Give the column a border: can't do this with the Box class JPanel col = new JPanel(); col.setLayout(new BoxLayout(col, BoxLayout.Y_AXIS)); col.setBorder(new TitledBorder(new EtchedBorder(), "Column")); for (int i = 0; i < 4; i++) { JButton b = new JButton("Button " + i); b.setFont(new Font("sanserif", Font.BOLD, 10 + i * 2)); col.add(b); } this.add(col, BorderLayout.EAST); // Add column to right of panel // Add a button box along the bottom of the panel. // Use "Glue" to space the buttons evenly Box buttonbox = Box.createHorizontalBox(); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Okay")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Cancel")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Help")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space this.add(buttonbox, BorderLayout.SOUTH); // Create a component to display in the center of the panel JTextArea textarea = new JTextArea(); textarea.setText("This component has 12-pixel margins on left and top" + " and has 72-pixel margins on right and bottom."); textarea.setLineWrap(true); textarea.setWrapStyleWord(true); // Use Box objects to give the JTextArea an unusual spacing // First, create a column with 3 kids. The first and last kids // are rigid spaces. The middle kid is the text area Box fixedcol = Box.createVerticalBox(); fixedcol.add(Box.createVerticalStrut(12)); // 12 rigid pixels fixedcol.add(textarea); // Component fills in the rest fixedcol.add(Box.createVerticalStrut(72)); // 72 rigid pixels // Now create a row. Give it rigid spaces on the left and right, // and put the column from above in the middle. Box fixedrow = Box.createHorizontalBox(); fixedrow.add(Box.createHorizontalStrut(12)); fixedrow.add(fixedcol); fixedrow.add(Box.createHorizontalStrut(72)); // Now add the JTextArea in the column in the row to the panel this.add(fixedrow, BorderLayout.CENTER); }
From source file:AnotherBorderTest.java
public AnotherBorderTest() { setTitle("Border Test"); setSize(450, 450);// www .j a v a 2 s. c om JPanel content = (JPanel) getContentPane(); content.setLayout(new GridLayout(6, 2, 3, 3)); 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("BALL.GIF"))); p.add(new JLabel("MatteBorder")); content.add(p); p = new JPanel(); p.setBorder(new TitledBorder(new MatteBorder(new ImageIcon("java2sLogo.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); }