List of usage examples for javax.swing JLabel setVerticalTextPosition
@BeanProperty(expert = true, visualUpdate = true, enumerationValues = { "SwingConstants.TOP", "SwingConstants.CENTER", "SwingConstants.BOTTOM" }, description = "The vertical position of the text relative to it's image.") public void setVerticalTextPosition(int textPosition)
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);//from ww w .j av a2 s .c o m frame.add(label1); 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 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);/*from www .j av a 2 s .c o m*/ frame.add(label1); 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);/* w w w.ja v a 2s . c o m*/ content.add(label1); 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:ImageLabelExample.java
protected static JLabel makeLabel(int vert, int horiz) { JLabel l = new JLabel("Smile", icon, SwingConstants.CENTER); l.setVerticalTextPosition(vert); l.setHorizontalTextPosition(horiz);// w ww .j a va 2s.co m l.setBorder(BorderFactory.createLineBorder(Color.black)); return l; }
From source file:StylesExample8.java
public static void createDocumentStyles(StyleContext sc) { Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); // Create and add the main document style Style mainStyle = sc.addStyle(mainStyleName, defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style Style cwStyle = sc.addStyle(charStyleName, null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style Style heading2Style = sc.addStyle(heading2StyleName, null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); // Create and add the Component style Class thisClass = StylesExample8.class; URL url = thisClass.getResource("java2s.gif"); ImageIcon icon = new ImageIcon(url); JLabel comp = new JLabel("Displaying text with attributes", icon, JLabel.CENTER); comp.setVerticalTextPosition(JLabel.BOTTOM); comp.setHorizontalTextPosition(JLabel.CENTER); comp.setFont(new Font("serif", Font.BOLD | Font.ITALIC, 14)); Style componentStyle = sc.addStyle(componentStyleName, null); StyleConstants.setComponent(componentStyle, comp); // The paragraph style for the component Style compParagraphStyle = sc.addStyle(compParaName, null); StyleConstants.setSpaceAbove(compParagraphStyle, (float) 16.0); }
From source file:TextPaneElements.java
public static void createDocumentStyles(StyleContext sc) { Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); // Create and add the main document style Style mainStyle = sc.addStyle(mainStyleName, defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style Style cwStyle = sc.addStyle(charStyleName, null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style Style heading2Style = sc.addStyle(heading2StyleName, null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); // Create and add the Component style Class thisClass = TextPaneElements.class; URL url = thisClass.getResource("java2s.gif"); ImageIcon icon = new ImageIcon(url); JLabel comp = new JLabel("Displaying text with attributes", icon, JLabel.CENTER); comp.setVerticalTextPosition(JLabel.BOTTOM); comp.setHorizontalTextPosition(JLabel.CENTER); comp.setFont(new Font("serif", Font.BOLD | Font.ITALIC, 14)); Style componentStyle = sc.addStyle(componentStyleName, null); StyleConstants.setComponent(componentStyle, comp); // The paragraph style for the component Style compParagraphStyle = sc.addStyle(compParaName, null); StyleConstants.setSpaceAbove(compParagraphStyle, (float) 16.0); }
From source file:components.LabelDemo.java
public LabelDemo() { super(new GridLayout(3, 1)); //3 rows, 1 column JLabel label1, label2, label3; ImageIcon icon = createImageIcon("images/middle.gif", "a pretty but meaningless splat"); //Create the first label. label1 = new JLabel("Image and Text", icon, JLabel.CENTER); //Set the position of its text, relative to its icon: label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setHorizontalTextPosition(JLabel.CENTER); //Create the other labels. label2 = new JLabel("Text-Only Label"); label3 = new JLabel(icon); //Create tool tips, for the heck of it. label1.setToolTipText("A label containing both image and text"); label2.setToolTipText("A label containing only text"); label3.setToolTipText("A label containing only an image"); //Add the labels. add(label1);/*from w w w. j a v a2 s . c o m*/ add(label2); add(label3); }
From source file:SwingLabelDemo.java
public SwingLabelDemo() { super(new GridLayout(3, 1)); //3 rows, 1 column JLabel label1, label2, label3; ImageIcon icon = createImageIcon("images/middle.gif", "a pretty but meaningless splat"); //Create the first label. label1 = new JLabel("Image and Text", icon, JLabel.CENTER); //Set the position of its text, relative to its icon: label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setHorizontalTextPosition(JLabel.CENTER); //Create the other labels. label2 = new JLabel("Text-Only Label"); label3 = new JLabel(icon); //Create tool tips, for the heck of it. label1.setToolTipText("A label containing both image and text"); label2.setToolTipText("A label containing only text"); label3.setToolTipText("A label containing only an image"); //Add the labels. add(label1);/*from w ww . j a v a 2s . c om*/ add(label2); add(label3); }
From source file:LabelDemo.java
public LabelDemo() { super("JLabel Demo"); setSize(600, 100);/*from www. j av a2s .c o m*/ JPanel content = new JPanel(new GridLayout(1, 4, 4, 4)); JLabel label = new JLabel("Java2s"); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s", SwingConstants.CENTER); label.setOpaque(true); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s"); label.setFont(new Font("Helvetica", Font.BOLD, 18)); label.setOpaque(true); label.setBackground(Color.white); content.add(label); ImageIcon image = new ImageIcon("java2sLogo.gif"); label = new JLabel("Java2s", image, SwingConstants.RIGHT); label.setVerticalTextPosition(SwingConstants.TOP); label.setOpaque(true); label.setBackground(Color.white); content.add(label); getContentPane().add(content); setVisible(true); }
From source file:Main.java
public Main() { super("JLabel Demo"); setSize(600, 100);//from w ww.j av a2s . c om JPanel content = new JPanel(new GridLayout(1, 4, 4, 4)); JLabel label = new JLabel("Java2s"); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s", SwingConstants.CENTER); label.setOpaque(true); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s"); label.setFont(new Font("Helvetica", Font.BOLD, 18)); label.setOpaque(true); label.setBackground(Color.white); content.add(label); ImageIcon image = new ImageIcon("java2sLogo.gif"); label = new JLabel("Java2s", image, SwingConstants.RIGHT); label.setVerticalTextPosition(SwingConstants.TOP); label.setOpaque(true); label.setBackground(Color.white); content.add(label); getContentPane().add(content); setVisible(true); }