List of usage examples for javax.swing SwingConstants BOTTOM
int BOTTOM
To view the source code for javax.swing SwingConstants BOTTOM.
Click Source Link
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);/*from ww w . j a v a 2 s.c om*/ 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:Main.java
public static void main(String[] argv) throws Exception { JButton button = new JButton(); // Place text over center of icon; they both occupy the same space button.setVerticalTextPosition(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.CENTER); // Place text above icon button.setVerticalTextPosition(SwingConstants.TOP); button.setHorizontalTextPosition(SwingConstants.CENTER); // Place text below icon button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.CENTER); // Place text to the left of icon, vertically centered button.setVerticalTextPosition(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.LEFT); // Place text to the left of icon and align their tops button.setVerticalTextPosition(SwingConstants.TOP); button.setHorizontalTextPosition(SwingConstants.LEFT); // Place text to the left of icon and align their bottoms button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.LEFT); // Place text to the right of icon, vertically centered button.setVerticalTextPosition(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.RIGHT); // Place text to the right of icon and align their tops button.setVerticalTextPosition(SwingConstants.TOP); button.setHorizontalTextPosition(SwingConstants.RIGHT); // Place text to the right of icon and align their bottoms button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.RIGHT); }
From source file:Main.java
/** * Initializes a default margin in provided directions. * <p>//from w w w.j av a 2 s.co m * Directions provided can be one of the TOP, LEFT, DOWN and BOTTOM * constants from the {@link SwingConstants} interface. * * @param directions Array of directions where the border is to be created. * @return Empty border to be used as margin; border width defined as * {@link #DEFAULT_MARGIN}. */ public static Border defaultMargin(int... directions) { int[] borders = new int[4]; if (directions == null) return BorderFactory.createEmptyBorder(); for (int i = 0; i < directions.length; i++) { if (directions[i] == SwingConstants.TOP) borders[0] = DEFAULT_MARGIN; if (directions[i] == SwingConstants.LEFT) borders[1] = DEFAULT_MARGIN; if (directions[i] == SwingConstants.BOTTOM) borders[2] = DEFAULT_MARGIN; if (directions[i] == SwingConstants.RIGHT) borders[3] = DEFAULT_MARGIN; } return BorderFactory.createEmptyBorder(borders[0], borders[1], borders[2], borders[3]); }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton jb = new JButton("Ok", new ImageIcon("bullet.gif")); jb.setHorizontalAlignment(SwingConstants.LEFT); jb.setMnemonic('O'); getContentPane().add(jb, BorderLayout.CENTER); jb = new JButton("<html><i>Cancel</i></html>"); jb.setVerticalAlignment(SwingConstants.BOTTOM); jb.setDefaultCapable(true);/*from ww w . j a v a2 s.co m*/ getContentPane().add(jb, BorderLayout.EAST); getRootPane().setDefaultButton(jb); setSize(200, 100); setVisible(true); }
From source file:fr.pasteque.pos.sales.restaurant.Place.java
public Place(JSONObject o) { this.m_sId = o.getString("id"); this.m_sName = o.getString("label"); this.m_ix = o.getInt("x"); this.m_iy = o.getInt("y"); this.m_sfloor = o.getString("floorId"); m_bPeople = false;//from w w w .j av a 2 s .c om m_btn = new JButton(); m_btn.setFocusPainted(false); m_btn.setFocusable(false); m_btn.setRequestFocusEnabled(false); m_btn.setHorizontalTextPosition(SwingConstants.CENTER); m_btn.setVerticalTextPosition(SwingConstants.BOTTOM); m_btn.setIcon(ICO_FRE); m_btn.setText(m_sName); }
From source file:PaintUtils.java
/** * Returns the bounds that the text of a label will be drawn into. * Takes into account the current font metrics. *//* ww w . ja v a2 s . c o m*/ public static Rectangle getTextBounds(Graphics g, JLabel label) { FontMetrics fm = g.getFontMetrics(); Rectangle2D r2d = fm.getStringBounds(label.getText(), g); Rectangle rect = r2d.getBounds(); int xOffset = 0; switch (label.getHorizontalAlignment()) { case SwingConstants.RIGHT: case SwingConstants.TRAILING: xOffset = label.getBounds().width - rect.width; break; case SwingConstants.CENTER: xOffset = (label.getBounds().width - rect.width) / 2; break; default: case SwingConstants.LEFT: case SwingConstants.LEADING: xOffset = 0; break; } int yOffset = 0; switch (label.getVerticalAlignment()) { case SwingConstants.TOP: yOffset = 0; break; case SwingConstants.CENTER: yOffset = (label.getBounds().height - rect.height) / 2; break; case SwingConstants.BOTTOM: yOffset = label.getBounds().height - rect.height; break; } return new Rectangle(xOffset, yOffset, rect.width, rect.height); }
From source file:com.lfv.lanzius.server.WorkspacePanel.java
private void initComponents() { view = new WorkspaceView(server, this); toolBar = new JToolBar(Config.TITLE + " - Toolbar"); buttonServer = new JButton(); buttonLink = new JButton(); buttonLoad = new JButton(); buttonUnlink = new JButton(); buttonSwap = new JButton(); buttonMonitor = new JButton(); buttonStart = new JButton(); buttonStop = new JButton(); buttonIsaStart = new JButton(); //buttonIsaToggle = new JButton(); setLayout(new BorderLayout()); iconServerOn = new ImageIcon("data/resources/icons/Server_on.png"); iconServerOff = new ImageIcon("data/resources/icons/Server_off.png"); buttonServer.setFont(new Font("Dialog", 0, 10)); buttonServer.setIcon(iconServerOff); buttonServer.setText("Server"); buttonServer.setDisabledIcon(iconServerOff); buttonServer.setEnabled(false);//from w w w . j av a 2 s . c om buttonServer.setFocusPainted(false); buttonServer.setHorizontalTextPosition(SwingConstants.CENTER); buttonServer.setIconTextGap(0); buttonServer.setVerticalTextPosition(SwingConstants.BOTTOM); toolBar.add(buttonServer); toolBar.addSeparator(new Dimension(40, 1)); buttonLoad.setFont(new Font("Dialog", 0, 10)); buttonLoad.setIcon(new ImageIcon("data/resources/icons/Load.png")); buttonLoad.setText("Load"); buttonLoad.setToolTipText("Load an exercise xml file"); buttonLoad.setDisabledIcon(new ImageIcon("data/resources/icons/Load_gray.png")); buttonLoad.setEnabled(false); buttonLoad.setFocusPainted(false); buttonLoad.setHorizontalTextPosition(SwingConstants.CENTER); buttonLoad.setIconTextGap(0); buttonLoad.setVerticalTextPosition(SwingConstants.BOTTOM); buttonLoad.addActionListener(this); toolBar.add(buttonLoad); toolBar.addSeparator(); buttonLink.setFont(new Font("Dialog", 0, 10)); buttonLink.setIcon(new ImageIcon("data/resources/icons/Link.png")); buttonLink.setText("Link"); buttonLink.setToolTipText("Link one or more players to the selected terminal"); buttonLink.setDisabledIcon(new ImageIcon("data/resources/icons/Link_gray.png")); buttonLink.setEnabled(false); buttonLink.setFocusPainted(false); buttonLink.setHorizontalTextPosition(SwingConstants.CENTER); buttonLink.setIconTextGap(0); buttonLink.setVerticalTextPosition(SwingConstants.BOTTOM); buttonLink.addActionListener(this); toolBar.add(buttonLink); buttonUnlink.setFont(new Font("Dialog", 0, 10)); buttonUnlink.setIcon(new ImageIcon("data/resources/icons/Unlink.png")); buttonUnlink.setText("Unlink"); buttonUnlink.setToolTipText("Unlink players from selected terminal(s) or group(s)"); buttonUnlink.setDisabledIcon(new ImageIcon("data/resources/icons/Unlink_gray.png")); buttonUnlink.setEnabled(false); buttonUnlink.setFocusPainted(false); buttonUnlink.setHorizontalTextPosition(SwingConstants.CENTER); buttonUnlink.setIconTextGap(0); buttonUnlink.setVerticalTextPosition(SwingConstants.BOTTOM); buttonUnlink.addActionListener(this); toolBar.add(buttonUnlink); buttonSwap.setFont(new Font("Dialog", 0, 10)); buttonSwap.setIcon(new ImageIcon("data/resources/icons/Swap.png")); buttonSwap.setText("Swap"); buttonSwap.setToolTipText("Swap the players linked to the two selected terminals"); buttonSwap.setDisabledIcon(new ImageIcon("data/resources/icons/Swap_gray.png")); buttonSwap.setEnabled(false); buttonSwap.setFocusPainted(false); buttonSwap.setHorizontalTextPosition(SwingConstants.CENTER); buttonSwap.setIconTextGap(0); buttonSwap.setVerticalTextPosition(SwingConstants.BOTTOM); buttonSwap.addActionListener(this); toolBar.add(buttonSwap); toolBar.addSeparator(); buttonMonitor.setFont(new Font("Dialog", 0, 10)); buttonMonitor.setIcon(new ImageIcon("data/resources/icons/Listen.png")); buttonMonitor.setText("Monitor"); buttonMonitor.setToolTipText("Listen and record the selected terminal"); buttonMonitor.setDisabledIcon(new ImageIcon("data/resources/icons/Listen_gray.png")); buttonMonitor.setEnabled(false); buttonMonitor.setFocusPainted(false); buttonMonitor.setHorizontalTextPosition(SwingConstants.CENTER); buttonMonitor.setIconTextGap(0); buttonMonitor.setVerticalTextPosition(SwingConstants.BOTTOM); buttonMonitor.addActionListener(this); toolBar.add(buttonMonitor); toolBar.addSeparator(); buttonStart.setFont(new Font("Dialog", 0, 10)); buttonStart.setIcon(new ImageIcon("data/resources/icons/Start.png")); buttonStart.setText("Start"); buttonStart.setToolTipText("Start the selected group(s)"); buttonStart.setDisabledIcon(new ImageIcon("data/resources/icons/Start_gray.png")); buttonStart.setEnabled(false); buttonStart.setFocusPainted(false); buttonStart.setHorizontalTextPosition(SwingConstants.CENTER); buttonStart.setIconTextGap(0); buttonStart.setVerticalTextPosition(SwingConstants.BOTTOM); buttonStart.addActionListener(this); toolBar.add(buttonStart); buttonStop.setFont(new Font("Dialog", 0, 10)); buttonStop.setIcon(new ImageIcon("data/resources/icons/Stop.png")); buttonStop.setText("Stop"); buttonStop.setToolTipText("Stop the selected group(s)"); buttonStop.setDisabledIcon(new ImageIcon("data/resources/icons/Stop_gray.png")); buttonStop.setEnabled(false); buttonStop.setFocusPainted(false); buttonStop.setHorizontalTextPosition(SwingConstants.CENTER); buttonStop.setIconTextGap(0); buttonStop.setVerticalTextPosition(SwingConstants.BOTTOM); buttonStop.addActionListener(this); toolBar.add(buttonStop); toolBar.addSeparator(); buttonIsaStart.setFont(new Font("Dialog", 0, 10)); buttonIsaStart.setIcon(new ImageIcon("data/resources/icons/StartISA.png")); buttonIsaStart.setText("ISA Start/Stop"); buttonIsaStart.setToolTipText("Start measure work load for selected clients"); buttonIsaStart.setDisabledIcon(new ImageIcon("data/resources/icons/StartISA_gray.png")); buttonIsaStart.setEnabled(true); buttonIsaStart.setFocusPainted(false); buttonIsaStart.setHorizontalTextPosition(SwingConstants.CENTER); buttonIsaStart.setIconTextGap(0); buttonIsaStart.setVerticalTextPosition(SwingConstants.BOTTOM); buttonIsaStart.addActionListener(this); toolBar.add(buttonIsaStart); /* buttonIsaToggle.setFont(new Font("Dialog", 0, 10)); buttonIsaToggle.setIcon(new ImageIcon("data/resources/icons/StopISA.png")); buttonIsaToggle.setText("Toggle ISA"); buttonIsaToggle.setToolTipText("Start/Stop measure work load for selected clients"); buttonIsaToggle.setDisabledIcon(new ImageIcon("data/resources/icons/StopISA_gray.png")); buttonIsaToggle.setEnabled(false); buttonIsaToggle.setFocusPainted(false); buttonIsaToggle.setHorizontalTextPosition(SwingConstants.CENTER); buttonIsaToggle.setIconTextGap(0); buttonIsaToggle.setVerticalTextPosition(SwingConstants.BOTTOM); buttonIsaToggle.addActionListener(this); toolBar.add(buttonIsaToggle); */ add(toolBar, BorderLayout.NORTH); add(view, BorderLayout.CENTER); }
From source file:king.flow.action.business.InsertCardAction.java
@Override protected void installButtonAction() { JButton btn = (JButton) this.owner; btn.addActionListener(new ActionListener() { @Override// w w w .ja va 2s .com public void actionPerformed(ActionEvent e) { if (cardType == DeviceEnum.GZ_CARD) { progressTip = new JLabel( getResourceMsg("operation.ic.card.insert.prompt" + "." + DeviceEnum.GZ_CARD.value())); } else { progressTip = new JLabel(getResourceMsg("operation.ic.card.insert.prompt")); } Window windowNode = getWindowNode(); UiStyle uiStyle = windowNode.getUiStyle(); if (uiStyle != null && uiStyle.getFont() != null && uiStyle.getFont().getName() != null) { progressTip.setFont(new FontUIResource(uiStyle.getFont().getName(), java.awt.Font.BOLD, 50)); } else { progressTip.setFont(new FontUIResource("Dialog", java.awt.Font.BOLD, 50)); } progressTip.setHorizontalAlignment(SwingConstants.CENTER); progressTip.setVerticalAlignment(SwingConstants.BOTTOM); final JDialog progressAnimation = buildAnimationDialog(animationFile); progressTip.setBounds(0, 120, progressAnimation.getBounds().width, 80); progressAnimation.getContentPane().add(progressTip, 1); final ImageIcon bgImage = CommonUtil.getImageIcon("/image/2.jpg"); //final ImageIcon bgImage = CommonUtil.getDefaultBackgroundImage(); if (bgImage != null) { progressAnimation.getContentPane().add(new JLabel(bgImage), 2); } else { progressAnimation.getContentPane().add(new JLabel(), 2); } switch (cardType) { case GZ_CARD: waitCommunicationTask(new GZReadCardTask(), progressAnimation); break; default: getLogger(InsertCardAction.class.getName()).log(Level.WARNING, "Unsupported card type[{0}] for InsertCardAction", cardType.name()); handleErr(getResourceMsg(GzCardConductor.GUOZHEN_CARD_OPERATION_PROMPT)); } } }); }
From source file:com.anrisoftware.prefdialog.core.AbstractTitleField.java
@Override public void setTitlePosition(TextPosition position) { super.setTitlePosition(position); switch (position) { case ICON_ONLY: titleLabel.setText(null);/*from www . j av a 2s . co m*/ break; case TEXT_ALONGSIDE_ICON: updateTitleResource(); updateIconResource(); titleLabel.setVerticalTextPosition(SwingConstants.CENTER); break; case TEXT_ONLY: updateTitleResource(); titleLabel.setIcon(null); break; case TEXT_UNDER_ICON: updateIconResource(); updateTitleResource(); titleLabel.setVerticalTextPosition(SwingConstants.BOTTOM); break; default: break; } }
From source file:edu.ku.brc.specify.plugins.TaxonLabelFormatting.java
@Override public void initialize(Properties propertiesArg, boolean isViewModeArg) { super.initialize(propertiesArg, isViewModeArg); String plName = "TaxonLabelFormatter"; PickListDBAdapterIFace adapter = PickListDBAdapterFactory.getInstance().create(plName, false); if (adapter == null || adapter.getPickList() == null) { throw new RuntimeException("PickList Adapter [" + plName + "] cannot be null!"); }// w ww . j a va2s . com formatCBX = new ValComboBox(adapter); formatCBX.getComboBox().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doFormatting(); } }); formatCBX.getComboBox().addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { doFormatting(); } }); newAgentBtn = createButton(""); // Label set when new Resource Bundle is installed (below) searchPanel = new DBObjSearchPanel("Search", "AgentNameSearch", "AgentNameSearch", "edu.ku.brc.specify.datamodel.Agent", "agentId", SwingConstants.BOTTOM); searchPanel.getScrollPane().setMinimumSize(new Dimension(100, 200)); searchPanel.getScrollPane().setPreferredSize(new Dimension(100, 150)); ((FormViewObj) searchPanel.getForm()).getPanel().setBorder(null); try { UIRegistry.loadAndPushResourceBundle("specify_plugins"); newAgentBtn.setText(getResourceString("NewAgent")); authorsList = new JList(new DefaultListModel()); authorsList.setVisibleRowCount(10); authorsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object selObj = authorsList.getSelectedValue(); if (selObj != null) { } updateEnabledState(); } } }); JScrollPane scrollPane = new JScrollPane(authorsList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); mapToBtn = createIconBtn("Map", "ADD_AUTHOR_NAME_TT", new ActionListener() { public void actionPerformed(ActionEvent ae) { Object agent = searchPanel.getSelectedObject(); ((DefaultListModel) authorsList.getModel()).addElement(agent); doFormatting(); } }); unmapBtn = createIconBtn("Unmap", "REMOVE_AUTHOR_NAME_TT", new ActionListener() { public void actionPerformed(ActionEvent ae) { int index = authorsList.getSelectedIndex(); if (index > -1) { DefaultListModel model = (DefaultListModel) authorsList.getModel(); model.remove(index); updateEnabledState(); doFormatting(); } } }); upBtn = createIconBtn("ReorderUp", "MOVE_AUTHOR_NAME_UP", new ActionListener() { public void actionPerformed(ActionEvent ae) { DefaultListModel model = (DefaultListModel) authorsList.getModel(); int index = authorsList.getSelectedIndex(); Object item = authorsList.getSelectedValue(); model.remove(index); model.insertElementAt(item, index - 1); authorsList.setSelectedIndex(index - 1); updateEnabledState(); } }); downBtn = createIconBtn("ReorderDown", "MOVE_AUTHOR_NAME_DOWN", new ActionListener() { public void actionPerformed(ActionEvent ae) { DefaultListModel model = (DefaultListModel) authorsList.getModel(); int index = authorsList.getSelectedIndex(); Object item = authorsList.getSelectedValue(); model.remove(index); model.insertElementAt(item, index + 1); authorsList.setSelectedIndex(index + 1); updateEnabledState(); } }); PanelBuilder bldr = new PanelBuilder(new FormLayout("p, 5px, p, 5px, f:p:g, 2px, p", "p, 4px, p, 2px, f:p:g, 4px, p, 4px, p, 2px, p, 2px, p, 2px, p"), this); CellConstraints cc = new CellConstraints(); PanelBuilder upDownPanel = new PanelBuilder(new FormLayout("p", "p, 2px, p, f:p:g")); upDownPanel.add(upBtn, cc.xy(1, 1)); upDownPanel.add(downBtn, cc.xy(1, 3)); PanelBuilder middlePanel = new PanelBuilder(new FormLayout("c:p:g", "f:p:g, p, 2px, p, f:p:g")); middlePanel.add(mapToBtn, cc.xy(1, 2)); middlePanel.add(unmapBtn, cc.xy(1, 4)); PanelBuilder rwPanel = new PanelBuilder(new FormLayout("p, 2px, f:p:g", "p")); refWorkLabel = createLabel(getResourceString("NONE")); rwPanel.add(createI18NFormLabel("REFERENCEWORK"), cc.xy(1, 1)); rwPanel.add(refWorkLabel, cc.xy(3, 1)); int y = 1; bldr.add(rwPanel.getPanel(), cc.xywh(1, y, 7, 1)); y += 2; bldr.add(searchPanel, cc.xywh(1, y, 1, 3)); bldr.addSeparator(getResourceString("Authors"), cc.xy(5, y)); y += 2; bldr.add(middlePanel.getPanel(), cc.xy(3, y)); bldr.add(scrollPane, cc.xywh(5, y, 1, 3)); bldr.add(upDownPanel.getPanel(), cc.xy(7, y)); y += 2; PanelBuilder newAgentPanel = new PanelBuilder(new FormLayout("f:p:g,p", "p")); newAgentPanel.add(newAgentBtn, cc.xy(2, 1)); bldr.add(newAgentPanel.getPanel(), cc.xy(1, y)); y += 2; JLabel fmtLabel = createLabel(getResourceString("LABELFORMAT")); bldr.add(fmtLabel, cc.xy(1, y)); y += 2; bldr.add(formatCBX, cc.xywh(1, y, 7, 1)); y += 2; Font plain = fmtLabel.getFont(); specialLabel = new SpecialLabel(plain, new Font(plain.getName(), Font.ITALIC, plain.getSize())); specialLabel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); bldr.add(createLabel(getResourceString("SAMPLEOUTPUT") + ":"), cc.xywh(1, y, 7, 1)); y += 2; bldr.add(specialLabel, cc.xywh(1, y, 7, 1)); searchPanel.setOKBtn(mapToBtn); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaxonLabelFormatting.class, ex); log.error(ex); ex.printStackTrace(); } UIRegistry.popResourceBundle(); }