List of usage examples for javax.swing SwingConstants LEADING
int LEADING
To view the source code for javax.swing SwingConstants LEADING.
Click Source Link
From source file:Main.java
public static int asHAlign(String val) { if (val.equals("leading")) return SwingConstants.LEADING; else if (val.equals("trailing")) return SwingConstants.TRAILING; else if (val.equals("left")) return SwingConstants.LEFT; else if (val.equals("right")) return SwingConstants.RIGHT; else if (val.equals("center")) return SwingConstants.CENTER; assert false; return -1;/*from w w w. j a v a 2 s .c o m*/ }
From source file:Main.java
public static JLabel createLabel(String text) { return createLabel(text, SwingConstants.LEADING); }
From source file:Main.java
public static Window showBelow(Component parent, Window window, int horizontalAlignment) { final int DISTANCE = 2; if (null == parent) throw new IllegalArgumentException("parent null"); if (null == window) throw new IllegalArgumentException("parent null"); if (!((SwingConstants.LEADING == horizontalAlignment) || (SwingConstants.TRAILING == horizontalAlignment) || (SwingConstants.CENTER == horizontalAlignment) || (SwingConstants.SOUTH == horizontalAlignment))) { throw new IllegalArgumentException("Illegal horizontal alignment " + horizontalAlignment + " should be either SwingConstants.LEADING or " + "SwingConstants.TRAILING or SwingConstants.CENTER"); }//from w w w. j av a 2 s .com window.pack(); Dimension windowSize = window.getPreferredSize(); Dimension parentSize = parent.getSize(); Point loc = parent.getLocationOnScreen(); int newX; if ((SwingConstants.CENTER == horizontalAlignment) || (SwingConstants.SOUTH == horizontalAlignment)) { newX = (parentSize.width - windowSize.width) / 2 + loc.x; } else if (SwingConstants.TRAILING == horizontalAlignment) { newX = loc.x + parentSize.width - windowSize.width; } else { newX = loc.x; } window.setLocation(newX, (loc.y + parentSize.height + DISTANCE)); window.setVisible(true); return window; }
From source file:LabelDnD2.java
public LabelDnD2() { super(new BorderLayout()); JColorChooser chooser = new JColorChooser(); chooser.setDragEnabled(true);//from w w w .j av a 2s . c o m label = new JLabel("I'm a Label and I accept color!", SwingConstants.LEADING); label.setTransferHandler(new TransferHandler("foreground")); MouseListener listener = new DragMouseAdapter(); label.addMouseListener(listener); JPanel lpanel = new JPanel(new GridLayout(1, 1)); TitledBorder t2 = BorderFactory.createTitledBorder("JLabel: drop color onto the label"); lpanel.add(label); lpanel.setBorder(t2); add(chooser, BorderLayout.CENTER); add(lpanel, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:LabelDnD.java
public LabelDnD() { super(new GridLayout(2, 1)); textField = new JTextField(40); textField.setDragEnabled(true);// w ww .j a v a2 s.c o m JPanel tfpanel = new JPanel(new GridLayout(1, 1)); TitledBorder t1 = BorderFactory.createTitledBorder("JTextField: drag and drop is enabled"); tfpanel.add(textField); tfpanel.setBorder(t1); label = new JLabel("I'm a Label!", SwingConstants.LEADING); label.setTransferHandler(new TransferHandler("text")); MouseListener listener = new DragMouseAdapter(); label.addMouseListener(listener); JPanel lpanel = new JPanel(new GridLayout(1, 1)); TitledBorder t2 = BorderFactory.createTitledBorder("JLabel: drag from or drop to this label"); lpanel.add(label); lpanel.setBorder(t2); add(tfpanel); add(lpanel); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:TabbedPaneTest.java
public TabbedPaneFrame() { setTitle("TabbedPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); tabbedPane = new JTabbedPane(); // we set the components to null and delay their loading until the tab is shown // for the first time ImageIcon icon = new ImageIcon("yellow-ball.gif"); tabbedPane.addTab("Mercury", icon, null); tabbedPane.addTab("Venus", icon, null); tabbedPane.addTab("Earth", icon, null); tabbedPane.addTab("Mars", icon, null); tabbedPane.addTab("Jupiter", icon, null); tabbedPane.addTab("Saturn", icon, null); tabbedPane.addTab("Uranus", icon, null); tabbedPane.addTab("Neptune", icon, null); tabbedPane.addTab("Pluto", null, null); final int plutoIndex = tabbedPane.indexOfTab("Pluto"); JPanel plutoPanel = new JPanel(); plutoPanel.add(new JLabel("Pluto", icon, SwingConstants.LEADING)); JToggleButton plutoCheckBox = new JCheckBox(); plutoCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tabbedPane.remove(plutoIndex); }//from w ww .j ava2 s .c om }); plutoPanel.add(plutoCheckBox); tabbedPane.setTabComponentAt(plutoIndex, plutoPanel); add(tabbedPane, "Center"); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { // check if this tab still has a null component if (tabbedPane.getSelectedComponent() == null) { // set the component to the image icon int n = tabbedPane.getSelectedIndex(); loadTab(n); } } }); loadTab(0); JPanel buttonPanel = new JPanel(); ButtonGroup buttonGroup = new ButtonGroup(); JRadioButton wrapButton = new JRadioButton("Wrap tabs"); wrapButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT); } }); buttonPanel.add(wrapButton); buttonGroup.add(wrapButton); wrapButton.setSelected(true); JRadioButton scrollButton = new JRadioButton("Scroll tabs"); scrollButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } }); buttonPanel.add(scrollButton); buttonGroup.add(scrollButton); add(buttonPanel, BorderLayout.SOUTH); }
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. *//*from w ww.j a va 2 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:net.sf.keystore_explorer.gui.dialogs.DCheckUpdate.java
private void initComponents() { jlCheckUpdate = new JLabel(res.getString("DCheckUpdate.jlCheckUpdate.text")); ImageIcon icon = new ImageIcon(getClass().getResource(res.getString("DCheckUpdate.jlCheckUpdate.image"))); jlCheckUpdate.setIcon(icon);/*from w w w .jav a 2 s. c o m*/ jlCheckUpdate.setHorizontalTextPosition(SwingConstants.LEADING); jlCheckUpdate.setIconTextGap(15); jpCheckUpdate = new JPanel(new FlowLayout(FlowLayout.CENTER)); jpCheckUpdate.add(jlCheckUpdate); jpCheckUpdate.setBorder(new EmptyBorder(5, 5, 5, 5)); jpbCheckUpdate = new JProgressBar(); jpbCheckUpdate.setIndeterminate(true); jpbCheckUpdate.setString("DCheckUpdate.jlCheckUpdate.text"); jpProgress = new JPanel(new FlowLayout(FlowLayout.CENTER)); jpProgress.add(jpbCheckUpdate); jpProgress.setBorder(new EmptyBorder(5, 5, 5, 5)); jbCancel = new JButton(res.getString("DCheckUpdate.jbCancel.text")); jbCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { cancelPressed(); } }); jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY); jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() { @Override public void actionPerformed(ActionEvent evt) { cancelPressed(); } }); jpCancel = PlatformUtil.createDialogButtonPanel(jbCancel, false); getContentPane().add(jpCheckUpdate, BorderLayout.NORTH); getContentPane().add(jpProgress, BorderLayout.CENTER); getContentPane().add(jpCancel, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { if ((checker != null) && (checker.isAlive())) { checker.interrupt(); } closeDialog(); } }); setTitle(res.getString("DCheckUpdate.Title")); setResizable(false); pack(); }
From source file:filterviewplugin.FilterViewSettingsTab.java
public JPanel createSettingsPanel() { final EnhancedPanelBuilder panelBuilder = new EnhancedPanelBuilder(FormFactory.RELATED_GAP_COLSPEC.encode() + ',' + FormFactory.PREF_COLSPEC.encode() + ',' + FormFactory.RELATED_GAP_COLSPEC.encode() + ',' + FormFactory.PREF_COLSPEC.encode() + ", fill:default:grow"); final CellConstraints cc = new CellConstraints(); final JLabel label = new JLabel(mLocalizer.msg("daysToShow", "Days to show")); panelBuilder.addRow();// w w w . ja v a 2 s .co m panelBuilder.add(label, cc.xy(2, panelBuilder.getRow())); final SpinnerNumberModel model = new SpinnerNumberModel(3, 1, 7, 1); mSpinner = new JSpinner(model); mSpinner.setValue(mSettings.getDays()); panelBuilder.add(mSpinner, cc.xy(4, panelBuilder.getRow())); panelBuilder.addParagraph(mLocalizer.msg("filters", "Filters to show")); mFilterList = new SelectableItemList(mSettings.getActiveFilterNames(), FilterViewSettings.getAvailableFilterNames()); mIcons.clear(); for (String filterName : FilterViewSettings.getAvailableFilterNames()) { mIcons.put(filterName, mSettings.getFilterIconName(mSettings.getFilter(filterName))); } mFilterList.addCenterRendererComponent(String.class, new SelectableItemRendererCenterComponentIf() { private DefaultListCellRenderer mRenderer = new DefaultListCellRenderer(); public void calculateSize(JList list, int index, JPanel contentPane) { } public JPanel createCenterPanel(JList list, Object value, int index, boolean isSelected, boolean isEnabled, JScrollPane parentScrollPane, int leftColumnWidth) { DefaultListCellRenderer label = (DefaultListCellRenderer) mRenderer .getListCellRendererComponent(list, value, index, isSelected, false); String filterName = value.toString(); String iconFileName = mIcons.get(filterName); Icon icon = null; if (!StringUtils.isEmpty(iconFileName)) { try { icon = FilterViewPlugin.getInstance().getIcon( FilterViewSettings.getIconDirectoryName() + File.separatorChar + iconFileName); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } label.setIcon(icon); } String text = filterName; if (icon == null) { text += " (" + mLocalizer.msg("noIcon", "no icon") + ')'; } label.setText(text); label.setHorizontalAlignment(SwingConstants.LEADING); label.setVerticalAlignment(SwingConstants.CENTER); label.setOpaque(false); JPanel panel = new JPanel(new BorderLayout()); if (isSelected && isEnabled) { panel.setOpaque(true); panel.setForeground(list.getSelectionForeground()); panel.setBackground(list.getSelectionBackground()); } else { panel.setOpaque(false); panel.setForeground(list.getForeground()); panel.setBackground(list.getBackground()); } panel.add(label, BorderLayout.WEST); return panel; } }); panelBuilder.addGrowingRow(); panelBuilder.add(mFilterList, cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1)); panelBuilder.addRow(); mFilterButton = new JButton(mLocalizer.msg("changeIcon", "Change icon")); mFilterButton.setEnabled(false); panelBuilder.add(mFilterButton, cc.xyw(2, panelBuilder.getRow(), 1)); mRemoveButton = new JButton(mLocalizer.msg("deleteIcon", "Remove icon")); mRemoveButton.setEnabled(false); panelBuilder.add(mRemoveButton, cc.xyw(4, panelBuilder.getRow(), 1)); mFilterButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SelectableItem item = (SelectableItem) mFilterList.getSelectedValue(); String filterName = (String) item.getItem(); chooseIcon(filterName); } }); mFilterList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { mFilterButton.setEnabled(mFilterList.getSelectedValue() != null); mRemoveButton.setEnabled(mFilterButton.isEnabled()); } }); mRemoveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SelectableItem item = (SelectableItem) mFilterList.getSelectedValue(); String filterName = (String) item.getItem(); mIcons.put(filterName, ""); mFilterList.updateUI(); } }); return panelBuilder.getPanel(); }
From source file:it.cnr.icar.eric.client.ui.swing.BusinessQueryPanel.java
/** * Class Constructor.// w w w . j a v a 2s.co m */ public BusinessQueryPanel(final FindParamsPanel findParamsPanel, ConfigurationType uiConfigurationType) throws JAXRException { super(findParamsPanel, uiConfigurationType); GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); objectTypeLabel = new JLabel(resourceBundle.getString("title.objectType"), SwingConstants.LEADING); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(objectTypeLabel, c); add(objectTypeLabel); //TODO: SwingBoost: Localize this TreeNode tempTreeNode = new DefaultMutableTreeNode("loading object types..."); objectTypeCombo = new it.cnr.icar.eric.client.ui.swing.TreeCombo(new DefaultTreeModel(tempTreeNode)); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 4, 4); gbl.setConstraints(objectTypeCombo, c); add(objectTypeCombo); objectTypeCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { if (ev.getStateChange() == ItemEvent.DESELECTED) { return; } @SuppressWarnings("unused") String objectType = getObjectType().toString(); } }); //The caseSensitive CheckBox caseSensitiveCheckBox = new JCheckBox(resourceBundle.getString("title.caseSensitiveSearch")); caseSensitiveCheckBox.setSelected(false); caseSensitiveCheckBox.setEnabled(true); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(caseSensitiveCheckBox, c); add(caseSensitiveCheckBox); //The name Text nameLabel = new JLabel(resourceBundle.getString("title.name"), SwingConstants.LEADING); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(nameLabel, c); add(nameLabel); nameText = new JTextField(); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 4, 4); gbl.setConstraints(nameText, c); add(nameText); nameText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { findParamsPanel.find(); } }); //The description text descLabel = new JLabel(resourceBundle.getString("title.description"), SwingConstants.LEADING); c.gridx = 0; c.gridy = 5; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(descLabel, c); add(descLabel); descText = new JTextField(); c.gridx = 0; c.gridy = 6; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 4, 4); gbl.setConstraints(descText, c); add(descText); descText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { findParamsPanel.find(); } }); //Classifications classificationsLabel = new JLabel(resourceBundle.getString("title.classifications"), SwingConstants.LEADING); c.gridx = 0; c.gridy = 7; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(classificationsLabel, c); add(classificationsLabel); classificationsList = new ClassificationsList(); classificationsList.setEditable(true); classificationsList.setVisibleRowCount(3); JScrollPane classificationsListScrollPane = new JScrollPane(classificationsList); //Workaround for bug 740746 where very wide item resulted in too short a height classificationsListScrollPane.setMinimumSize(new Dimension(-1, 50)); c.gridx = 0; c.gridy = 8; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.5; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 4, 4); gbl.setConstraints(classificationsListScrollPane, c); add(classificationsListScrollPane); //Identifiers identifiersLabel = new JLabel(resourceBundle.getString("title.externalIdentifiers"), SwingConstants.LEADING); c.gridx = 0; c.gridy = 9; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(identifiersLabel, c); add(identifiersLabel); extIdsList = new ExternalIdentifiersList(); extIdsList.setEditable(true); extIdsList.setVisibleRowCount(3); JScrollPane extIdsListScrollPane = new JScrollPane(extIdsList); //Workaround for bug 740746 where very wide item resulted in too short a height extIdsListScrollPane.setMinimumSize(new Dimension(-1, 50)); c.gridx = 0; c.gridy = 10; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.5; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 4, 4); gbl.setConstraints(extIdsListScrollPane, c); add(extIdsListScrollPane); //External Links linksLabel = new JLabel(resourceBundle.getString("title.externalLinks"), SwingConstants.TRAILING); c.gridx = 0; c.gridy = 11; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(linksLabel, c); add(linksLabel); linksList = new ExternalLinksList(); linksList.setEditable(true); linksList.setVisibleRowCount(3); JScrollPane linksListScrollPane = new JScrollPane(linksList); //Workaround for bug 740746 where very wide item resulted in too short a height linksListScrollPane.setMinimumSize(new Dimension(-1, 50)); c.gridx = 0; c.gridy = 12; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.5; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(4, 4, 4, 4); gbl.setConstraints(linksListScrollPane, c); add(linksListScrollPane); //add listener for 'locale' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this); }