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:events.FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);/*w w w.j av a2 s . com*/ GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; //Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField); c.weightx = 0.1; //Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector<String> vector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector<String> listVector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); //It's easier to see the focus change //if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; //Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; //Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); //The setRequestFocusEnabled method prevents a //component from being clickable, but it can still //get the focus through the keyboard - this ensures //user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); ((JPanel) pane).setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:AlignLabels.java
JLabel createLabel(String text) { String separator = System.getProperty("line.separator"); JLabel label = new JLabel(text + separator + "multiline" + separator + "label"); label.setToolTipText(text + "\n\ndoubled space\n\ntooltip"); label.setBorder(BorderFactory.createEtchedBorder()); this.add(label); label.setPreferredSize(new Dimension(125, 125)); return label; }
From source file:FocusEventDemo.java
public void addComponentsToPane(final Container pane) { GridBagLayout gridbag = new GridBagLayout(); pane.setLayout(gridbag);//from w w w .j a va 2 s . co m GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; // Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField); c.weightx = 0.1; // Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector<String> vector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector<String> listVector = new Vector<String>(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); // It's easier to see the focus change // if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; // Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; // Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); // The setRequestFocusEnabled method prevents a // component from being clickable, but it can still // get the focus through the keyboard - this ensures // user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); ((JPanel) pane).setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:FocusEventDemo.java
public FocusEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; //Make column as wide as possible. JTextField textField = new JTextField("A TextField"); textField.setMargin(new Insets(0, 2, 0, 2)); textField.addFocusListener(this); gridbag.setConstraints(textField, c); add(textField);/*from w w w . j a v a 2 s . c o m*/ c.weightx = 0.1; //Widen every other column a bit, when possible. c.fill = GridBagConstraints.NONE; JLabel label = new JLabel("A Label"); label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); label.addFocusListener(this); gridbag.setConstraints(label, c); add(label); String comboPrefix = "ComboBox Item #"; final int numItems = 15; Vector vector = new Vector(numItems); for (int i = 0; i < numItems; i++) { vector.addElement(comboPrefix + i); } JComboBox comboBox = new JComboBox(vector); comboBox.addFocusListener(this); gridbag.setConstraints(comboBox, c); add(comboBox); c.gridwidth = GridBagConstraints.REMAINDER; JButton button = new JButton("A Button"); button.addFocusListener(this); gridbag.setConstraints(button, c); add(button); c.weightx = 0.0; c.weighty = 0.1; c.fill = GridBagConstraints.BOTH; String listPrefix = "List Item #"; Vector listVector = new Vector(numItems); for (int i = 0; i < numItems; i++) { listVector.addElement(listPrefix + i); } JList list = new JList(listVector); list.setSelectedIndex(1); //It's easier to see the focus change //if an item is selected. list.addFocusListener(this); JScrollPane listScrollPane = new JScrollPane(list); //We want to prevent the list's scroll bars //from getting the focus - even with the keyboard. //Note that in general we prefer setRequestFocusable //over setFocusable for reasons of accessibility, //but this is to work around bug #4866958. listScrollPane.getVerticalScrollBar().setFocusable(false); listScrollPane.getHorizontalScrollBar().setFocusable(false); gridbag.setConstraints(listScrollPane, c); add(listScrollPane); c.weighty = 1.0; //Make this row as tall as possible. c.gridheight = GridBagConstraints.REMAINDER; //Set up the area that reports focus-gained and focus-lost events. display = new JTextArea(); display.setEditable(false); //The method setRequestFocusEnabled prevents a //component from being clickable, but it can still //get the focus through the keyboard - this ensures //user accessibility. display.setRequestFocusEnabled(false); display.addFocusListener(this); JScrollPane displayScrollPane = new JScrollPane(display); //Work around for bug #4866958. displayScrollPane.getHorizontalScrollBar().setFocusable(false); displayScrollPane.getVerticalScrollBar().setFocusable(false); gridbag.setConstraints(displayScrollPane, c); add(displayScrollPane); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:edu.gmu.cs.sim.util.media.chart.SeriesAttributes.java
/** Builds a SeriesAttributes with the provided generator, name for the series, and index for the series. Calls buildAttributes to construct custom elements in the LabelledList, then finally calls rebuildGraphicsDefinitions() to update the series. *//*w w w .jav a2s.c o m*/ public SeriesAttributes(ChartGenerator generator, String name, int index, SeriesChangeListener stoppable) { super(name); setStoppable(stoppable); this.generator = generator; seriesIndex = index; final JCheckBox check = new JCheckBox(); check.setSelected(true); check.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setPlotVisible(check.isSelected()); } }); manipulators = new Box(BoxLayout.X_AXIS); buildManipulators(); JLabel spacer = new JLabel(""); spacer.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); Box b = new Box(BoxLayout.X_AXIS); b.add(check); b.add(spacer); b.add(manipulators); b.add(Box.createGlue()); addLabelled("Show", b); final PropertyField nameF = new PropertyField(name) { public String newValue(String newValue) { SeriesAttributes.this.setSeriesName(newValue); rebuildGraphicsDefinitions(); return newValue; } }; addLabelled("Series", nameF); buildAttributes(); rebuildGraphicsDefinitions(); }
From source file:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java
@SuppressWarnings("unchecked") public OverviewDialog(Window window, String title, @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData, Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider, FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) { super(window, title, ModalityType.MODELESS); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setAlwaysOnTop(true);//from ww w .j a va2 s. c om this.fieldViewSelectionModel = fvsm; @SuppressWarnings({ "rawtypes" }) JComboBox activeTiCombo = new JComboBox(comboBoxModel); TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer( curationData.getTraitColorProvider(), tiNameProvider); activeTiCombo.setRenderer(tiCellRenderer); JLabel infoLabel = new JLabel(" "); infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED)); final JFrame[] helpDialog = new JFrame[1]; Action helpAction = new AbstractAction("?") { @Override public void actionPerformed(ActionEvent e) { if (helpDialog[0] != null) { GuiUtil.restoreFrame(helpDialog[0]); } else { JFrame f = new JFrame("Overview Help"); helpDialog[0] = f; f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setAlwaysOnTop(true); f.setLocationRelativeTo(overview); String html = Overview.getOverviewHelpHtml(); JLabel label = new JLabel(html); label.setBorder(new EmptyBorder(0, 10, 0, 10)); f.setContentPane(label); f.pack(); f.setVisible(true); } } }; // Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this); if (window != null) { if (window instanceof JFrame) { System.out.println("Found window: " + ((JFrame) window).getTitle()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); if (helpDialog[0] != null) { helpDialog[0].dispose(); } } }); } KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview"); Box top = Box.createHorizontalBox(); top.add(activeTiCombo); top.add(new JButton(helpAction)); overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel); overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true)); Container cp = getContentPane(); cp.add(top, BorderLayout.NORTH); // cp.add(traitLabel, BorderLayout.NORTH); cp.add(infoLabel, BorderLayout.SOUTH); cp.add(overview, BorderLayout.CENTER); pack(); // setResizable(false); // setLocationRelativeTo(showOverviewButton); // DEFAULT POSITION is "out of the way" setVisible(true); this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { toFront(); } @Override public void windowClosed(WindowEvent e) { fieldViewSelectionModel.removeListSelectionListener(listSelectionListener); removeWindowListener(this); } }); }
From source file:net.chunkyhosting.Roe.computer.CHGManager.gui.dialogs.DownloadNotice.java
public DownloadNotice(HashMap<JSONObject, URL> downloads) { this.setDownloads(downloads); JPanel basic = new JPanel(); basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS)); add(basic);/* w ww . jav a2 s .c om*/ JPanel topPanel = new JPanel(new BorderLayout(0, 0)); topPanel.setMaximumSize(new Dimension(450, 0)); JLabel hint = new JLabel("CHGManager Download Manager"); hint.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0)); topPanel.add(hint); JSeparator separator = new JSeparator(); separator.setForeground(Color.gray); topPanel.add(separator, BorderLayout.SOUTH); basic.add(topPanel); JPanel textPanel = new JPanel(new BorderLayout()); textPanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25)); this.setTextPanel(new JTextPane()); this.getTextPanel().setContentType("text/html"); String text = "<p><b>Some files are missing from your CHGManager install. Don't worry. We're trying to download them. Please don't close this panel!</b></p>"; this.getText().add(text); this.getTextPanel().setText(text); this.getTextPanel().setEditable(false); JScrollPane sp = new JScrollPane(); sp.setSize(this.getTextPanel().getSize()); basic.add(sp); //basic.add(textPanel); JPanel boxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 0)); basic.add(boxPanel); JPanel bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton close = new JButton("Close"); bottom.add(close); basic.add(bottom); bottom.setMaximumSize(new Dimension(450, 0)); this.setTitle("CHGManager Download Manager"); this.setResizable(false); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setLocationRelativeTo(null); this.setVisible(true); try { Thread.sleep(2000); } catch (InterruptedException e) { } this.startDownload(); }
From source file:net.sf.taverna.raven.plugins.ui.CheckForUpdatesDialog.java
private void initComponents() { // Base font for all components on the form Font baseFont = new JLabel("base font").getFont().deriveFont(11f); // Message saying that updates are available JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.setBorder(/*ww w .java 2 s. co m*/ new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(EtchedBorder.LOWERED))); JLabel message = new JLabel( "<html><body>Updates are available for some Taverna components. To review and <br>install them go to 'Updates and plugins' in the 'Advanced' menu.</body><html>"); message.setFont(baseFont.deriveFont(12f)); message.setBorder(new EmptyBorder(5, 5, 5, 5)); message.setIcon(UpdatesAvailableIcon.updateIcon); messagePanel.add(message, BorderLayout.CENTER); // Buttons JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton okButton = new JButton("OK"); // we'll check for updates again in 2 weeks okButton.setFont(baseFont); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okPressed(); } }); buttonsPanel.add(okButton); getContentPane().setLayout(new BorderLayout()); getContentPane().add(messagePanel, BorderLayout.CENTER); getContentPane().add(buttonsPanel, BorderLayout.SOUTH); pack(); setResizable(false); // Center the dialog on the screen (we do not have the parent) Dimension dimension = getToolkit().getScreenSize(); Rectangle abounds = getBounds(); setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2); setSize(getPreferredSize()); }
From source file:net.daboross.outputtablesclient.gui.OutputInterface.java
@Override public void onUpdate(final RobotTable table, final String key, final String value, final UpdateAction action) { if (!application.getOutput().getNameTable().contains(table.getName())) { return;// w ww.j av a2 s. com } if (action == UpdateAction.NEW) { // if (key.equalsIgnoreCase(":RangeGUI")) { // Output.oLog("Range: %s", value); // try { // application.getCustomInterface().setTo(Double.parseDouble(value)); // } catch (NumberFormatException ex) { // Output.oLog("Invalid range '%s'", value); // } // } ensureTableExists(table.getName()); JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(new LineBorder(Color.BLACK)); tableKeyAndKeyToValuePanel.get(table.getName()).put(key, panel); JLabel keyLabel = new JLabel(key); keyLabel.setBorder(new EmptyBorder(5, 5, 5, 5)); panel.add(keyLabel, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0)); JSeparator separator = new JSeparator(JSeparator.VERTICAL); separator.setPreferredSize(new Dimension(2, 20)); panel.add(separator, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0)); JLabel valueLabel = new JLabel(value); valueLabel.setBorder(new EmptyBorder(5, 5, 5, 5)); panel.add(valueLabel, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0)); tableKeyAndKeyToValueLabel.get(table.getName()).put(key, valueLabel); JPanel parentPanel = tableKeyToTablePanel.get(table.getName()); parentPanel.add(panel); parentPanel.revalidate(); } else if (action == UpdateAction.UPDATE) { // if (key.equalsIgnoreCase(":RangeGUI")) { // Output.oLog("Range: %s", value); // try { // application.getCustomInterface().setTo(Double.parseDouble(value)); // } catch (NumberFormatException ex) { // Output.oLog("Invalid range '%s'", value); // } // } ensureTableExists(table.getName()); JLabel valueLabel = tableKeyAndKeyToValueLabel.get(table.getName()).get(key); valueLabel.setText(value); } else if (action == UpdateAction.DELETE) { if (tableKeyToTablePanel.get(table.getName()) == null) { return; } JPanel parentPanel = tableKeyToTablePanel.get(table.getName()); JPanel valuePanel = tableKeyAndKeyToValuePanel.get(table.getName()).remove(key); parentPanel.remove(valuePanel); parentPanel.revalidate(); } }
From source file:LayeredPaneDemo.java
private JLabel createColoredLabel(String text, Color color, Point origin) { JLabel label = new JLabel(text); label.setVerticalAlignment(JLabel.TOP); label.setHorizontalAlignment(JLabel.CENTER); label.setOpaque(true);/* w w w. j av a2 s .c o m*/ label.setBackground(color); label.setForeground(Color.black); label.setBorder(BorderFactory.createLineBorder(Color.black)); label.setBounds(origin.x, origin.y, 140, 140); return label; }