List of usage examples for javax.swing JLabel setBorder
@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.") public void setBorder(Border border)
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(200, 360);// www. ja v a 2s. c o m f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel( "<html>Use HTML to create<br>" + "a multiline message." + "<br>One<br>Two<br>Three"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); f.add(label); f.setVisible(true); }
From source file:LabelHeaderSample.java
public static void main(String args[]) { Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" }, { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" }, { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" }, { "ten", "ju - \u5341" } }; JFrame frame = new JFrame("Label Header"); String headers[] = { "English", "Japanese" }; JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); Icon redIcon = new DiamondIcon(Color.red); Icon blueIcon = new DiamondIcon(Color.blue); Border headerBorder = UIManager.getBorder("TableHeader.cellBorder"); JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER); blueLabel.setBorder(headerBorder); JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER); redLabel.setBorder(headerBorder);/*from w w w. j ava2 s . c o m*/ TableCellRenderer renderer = new JComponentTableCellRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableColumn column0 = columnModel.getColumn(0); TableColumn column1 = columnModel.getColumn(1); column0.setHeaderRenderer(renderer); column0.setHeaderValue(blueLabel); column1.setHeaderRenderer(renderer); column1.setHeaderValue(redLabel); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:BorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border bevelBorder = new BevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Border emptyBorder = new EmptyBorder(5, 10, 5, 10); Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.red, Color.pink); Border lineBorder = new LineBorder(Color.red, 5); Icon diamondIcon = new DiamondIcon(Color.red); Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon); Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Font font = new Font("Serif", Font.ITALIC, 12); Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.red);/*from w w w.j a va2s.co m*/ Border compoundBorder = new CompoundBorder(lineBorder, matteBorder); JLabel bevelLabel = new JLabel("Bevel"); bevelLabel.setBorder(bevelBorder); bevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel emptyLabel = new JLabel("Empty"); emptyLabel.setBorder(emptyBorder); emptyLabel.setHorizontalAlignment(JLabel.CENTER); JLabel etchedLabel = new JLabel("Etched"); etchedLabel.setBorder(etchedBorder); etchedLabel.setHorizontalAlignment(JLabel.CENTER); JLabel lineLabel = new JLabel("Line"); lineLabel.setBorder(lineBorder); lineLabel.setHorizontalAlignment(JLabel.CENTER); JLabel matteLabel = new JLabel("Matte"); matteLabel.setBorder(matteBorder); matteLabel.setHorizontalAlignment(JLabel.CENTER); JLabel softBevelLabel = new JLabel("Soft Bevel"); softBevelLabel.setBorder(softBevelBorder); softBevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel titledLabel = new JLabel("Titled"); titledLabel.setBorder(titledBorder); titledLabel.setHorizontalAlignment(JLabel.CENTER); JLabel compoundLabel = new JLabel("Compound"); compoundLabel.setBorder(compoundBorder); compoundLabel.setHorizontalAlignment(JLabel.CENTER); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(2, 4, 5, 5)); contentPane.add(bevelLabel); contentPane.add(emptyLabel); contentPane.add(etchedLabel); contentPane.add(lineLabel); contentPane.add(matteLabel); contentPane.add(softBevelLabel); contentPane.add(titledLabel); contentPane.add(compoundLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:JColorChooserWithCustomPreviewPanel.java
public static void main(String[] a) { final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER); previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); previewLabel.setSize(previewLabel.getPreferredSize()); previewLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0)); JColorChooser colorChooser = new JColorChooser(); colorChooser.setPreviewPanel(previewLabel); JDialog d = colorChooser.createDialog(null, "", true, colorChooser, null, null); d.setVisible(true);//w ww . j a v a2 s. c o m }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Text Pos"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(2, 2)); Border border = LineBorder.createGrayLineBorder(); Icon warnIcon = MetalIconFactory.getTreeComputerIcon(); JLabel label1 = new JLabel(); label1.setText("Left-Bottom"); label1.setHorizontalTextPosition(JLabel.LEFT); label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setBorder(border); frame.add(label1);//from www . ja v a2 s . c o m JLabel label2 = new JLabel(warnIcon); label2.setText("Right-TOP"); label2.setHorizontalTextPosition(JLabel.RIGHT); label2.setVerticalTextPosition(JLabel.TOP); label2.setBorder(border); frame.add(label2); JLabel label3 = new JLabel(warnIcon); label3.setText("Center-Center"); label3.setHorizontalTextPosition(JLabel.CENTER); label3.setVerticalTextPosition(JLabel.CENTER); label3.setBorder(border); frame.add(label3); JLabel label4 = new JLabel(warnIcon); label4.setText("Center-Bottom"); label4.setHorizontalTextPosition(JLabel.CENTER); label4.setVerticalTextPosition(JLabel.BOTTOM); label4.setBorder(border); frame.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { final JColorChooser colorChooser = new JColorChooser(); final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER); previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); previewLabel.setSize(previewLabel.getPreferredSize()); previewLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0)); colorChooser.setPreviewPanel(previewLabel); ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("OK Button"); System.out.println(colorChooser.getColor()); }/* w w w. ja v a 2s . co m*/ }; ActionListener cancelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Cancel Button"); } }; final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser, okActionListener, cancelActionListener); dialog.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Text Pos"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(2, 2)); Border border = LineBorder.createGrayLineBorder(); Icon warnIcon = MetalIconFactory.getTreeComputerIcon(); JLabel label1 = new JLabel(warnIcon); label1.setText("Left-Bottom"); label1.setHorizontalTextPosition(JLabel.LEFT); label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setBorder(border); frame.add(label1);/*from w ww .j a va2s .co m*/ JLabel label2 = new JLabel(warnIcon); label2.setText("Right-TOP"); label2.setHorizontalTextPosition(JLabel.RIGHT); label2.setVerticalTextPosition(JLabel.TOP); label2.setBorder(border); frame.add(label2); JLabel label3 = new JLabel(warnIcon); label3.setText("Center-Center"); label3.setHorizontalTextPosition(JLabel.CENTER); label3.setVerticalTextPosition(JLabel.CENTER); label3.setBorder(border); frame.add(label3); JLabel label4 = new JLabel(warnIcon); label4.setText("Center-Bottom"); label4.setHorizontalTextPosition(JLabel.CENTER); label4.setVerticalTextPosition(JLabel.BOTTOM); label4.setBorder(border); frame.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:LabelTextPos.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Text Pos"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(2, 2)); Border border = LineBorder.createGrayLineBorder(); Icon warnIcon = new ImageIcon("Warn.gif"); JLabel label1 = new JLabel(warnIcon); label1.setText("Left-Bottom"); label1.setHorizontalTextPosition(JLabel.LEFT); label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setBorder(border); content.add(label1);/* w w w . j a v a 2 s.c o m*/ JLabel label2 = new JLabel(warnIcon); label2.setText("Right-TOP"); label2.setHorizontalTextPosition(JLabel.RIGHT); label2.setVerticalTextPosition(JLabel.TOP); label2.setBorder(border); content.add(label2); JLabel label3 = new JLabel(warnIcon); label3.setText("Center-Center"); label3.setHorizontalTextPosition(JLabel.CENTER); label3.setVerticalTextPosition(JLabel.CENTER); label3.setBorder(border); content.add(label3); JLabel label4 = new JLabel(warnIcon); label4.setText("Center-Bottom"); label4.setHorizontalTextPosition(JLabel.CENTER); label4.setVerticalTextPosition(JLabel.BOTTOM); label4.setBorder(border); content.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JLabel label1 = new JLabel("BottomRight", SwingConstants.RIGHT); JLabel label2 = new JLabel("CenterLeft", SwingConstants.LEFT); JLabel label3 = new JLabel("TopCenter", SwingConstants.CENTER); label1.setVerticalAlignment(SwingConstants.BOTTOM); label2.setVerticalAlignment(SwingConstants.CENTER); label3.setVerticalAlignment(SwingConstants.TOP); label1.setBorder(BorderFactory.createLineBorder(Color.black)); label2.setBorder(BorderFactory.createLineBorder(Color.black)); label3.setBorder(BorderFactory.createLineBorder(Color.black)); JFrame frame = new JFrame("AlignmentExample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(new GridLayout(3, 1, 8, 8)); p.add(label1);//w ww . j a v a 2s .c o m p.add(label2); p.add(label3); p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); frame.setContentPane(p); frame.setSize(200, 200); frame.setVisible(true); }
From source file:DisplayMessage.java
public static void main(String[] args) { /*//from w ww. j a va2 s . c om * Step 1: Create the components */ JLabel msgLabel = new JLabel(); // Component to display the question JButton yesButton = new JButton(); // Button for an affirmative response JButton noButton = new JButton(); // Button for a negative response /* * Step 2: Set properties of the components */ msgLabel.setText(args[0]); // The msg to display msgLabel.setBorder(new EmptyBorder(10, 10, 10, 10)); // A 10-pixel margin yesButton.setText((args.length >= 2) ? args[1] : "Yes"); // Text for Yes button noButton.setText((args.length >= 3) ? args[2] : "No"); // Text for no button /* * Step 3: Create containers to hold the components */ JFrame win = new JFrame("Message"); // The main application window JPanel buttonbox = new JPanel(); // A container for the two buttons /* * Step 4: Specify LayoutManagers to arrange components in the containers */ win.getContentPane().setLayout(new BorderLayout()); // layout on borders buttonbox.setLayout(new FlowLayout()); // layout left-to-right /* * Step 5: Add components to containers, with optional layout constraints */ buttonbox.add(yesButton); // add yes button to the panel buttonbox.add(noButton); // add no button to the panel // add JLabel to window, telling the BorderLayout to put it in the middle win.getContentPane().add(msgLabel, "Center"); // add panel to window, telling the BorderLayout to put it at the bottom win.getContentPane().add(buttonbox, "South"); /* * Step 6: Arrange to handle events in the user interface. */ yesButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the Yes button is clicked. public void actionPerformed(ActionEvent e) { System.exit(0); } }); noButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the No button is clicked. public void actionPerformed(ActionEvent e) { System.exit(1); } }); /* * Step 7: Display the GUI to the user */ win.pack(); // Set the size of the window based its children's sizes. win.show(); // Make the window visible. }