List of usage examples for javax.swing JLabel setHorizontalTextPosition
@BeanProperty(expert = true, visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER", "SwingConstants.RIGHT", "SwingConstants.LEADING", "SwingConstants.TRAILING" }, description = "The horizontal position of the label's text, relative to its image.") public void setHorizontalTextPosition(int textPosition)
From source file:TestOval.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label1 = new JLabel(new OvalIcon(20, 50)); JLabel label2 = new JLabel(new OvalIcon(50, 20)); JLabel label3 = new JLabel("Round!", new OvalIcon(60, 60), SwingConstants.CENTER); label3.setHorizontalTextPosition(SwingConstants.CENTER); Container c = f.getContentPane(); c.setLayout(new FlowLayout()); c.add(label1);/*from w w w . jav a 2 s.c o m*/ c.add(label2); c.add(label3); f.pack(); f.setVisible(true); }
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);/*w w w . j a v 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: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 ww w . j av a2 s .com 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);//from w ww. j ava 2 s .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);//from w w w .j a va 2 s . co m l.setHorizontalTextPosition(horiz); 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);/* w w w . j a v a2 s . com*/ 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);//ww w .j a v a 2 s .co m add(label2); add(label3); }
From source file:com.atlassian.theplugin.idea.config.serverconfig.GenericServerConfigForm.java
/** * Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< * DO NOT edit this method OR call it in your code! * * @noinspection ALL/* w ww .j ava 2 s.co m*/ */ private void $$$setupUI$$$() { rootComponent = new JPanel(); rootComponent.setLayout(new GridBagLayout()); final JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayoutManager(7, 3, new Insets(0, 0, 0, 0), -1, -1)); GridBagConstraints gbc; gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.BOTH; rootComponent.add(panel1, gbc); serverName = new JTextField(); serverName.setText(""); panel1.add(serverName, new GridConstraints(1, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label1 = new JLabel(); label1.setHorizontalAlignment(4); label1.setHorizontalTextPosition(4); label1.setText("Server Name:"); label1.setDisplayedMnemonic('S'); label1.setDisplayedMnemonicIndex(0); panel1.add(label1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(80, -1), new Dimension(92, 16), null, 0, false)); serverUrl = new JTextField(); panel1.add(serverUrl, new GridConstraints(2, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); username = new JTextField(); panel1.add(username, new GridConstraints(3, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); password = new JPasswordField(); panel1.add(password, new GridConstraints(4, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label2 = new JLabel(); label2.setHorizontalAlignment(4); label2.setText("Server URL:"); label2.setDisplayedMnemonic('U'); label2.setDisplayedMnemonicIndex(7); panel1.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(80, -1), new Dimension(92, 16), null, 0, false)); final JLabel label3 = new JLabel(); label3.setHorizontalAlignment(4); label3.setText("Username:"); label3.setDisplayedMnemonic('N'); label3.setDisplayedMnemonicIndex(4); panel1.add(label3, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(92, 16), null, 0, false)); final JLabel label4 = new JLabel(); label4.setHorizontalAlignment(4); label4.setText("Password:"); label4.setDisplayedMnemonic('P'); label4.setDisplayedMnemonicIndex(0); panel1.add(label4, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(92, 16), null, 0, false)); testConnection = new JButton(); testConnection.setText("Test Connection"); testConnection.setMnemonic('T'); testConnection.setDisplayedMnemonicIndex(0); panel1.add(testConnection, new GridConstraints(5, 2, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); // chkPasswordRemember = new JCheckBox(); // chkPasswordRemember.setSelected(true); // chkPasswordRemember.setText("Remember Password"); // chkPasswordRemember.setMnemonic('R'); // chkPasswordRemember.setDisplayedMnemonicIndex(0); // panel1.add(chkPasswordRemember, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, // GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, // null, null, null, 0, false)); cbEnabled = new JCheckBox(); cbEnabled.setEnabled(false); cbEnabled.setHorizontalTextPosition(11); cbEnabled.setText("Server Enabled"); cbEnabled.setMnemonic('E'); cbEnabled.setDisplayedMnemonicIndex(7); panel1.add(cbEnabled, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(115, 25), null, 0, false)); useDefault = new JCheckBox(); useDefault.setText("Use Default Credentials"); panel1.add(useDefault, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JPanel spacer1 = new JPanel(); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.VERTICAL; rootComponent.add(spacer1, gbc); label1.setLabelFor(serverName); label2.setLabelFor(serverUrl); label3.setLabelFor(username); label4.setLabelFor(password); }