Example usage for javax.swing JLabel setBounds

List of usage examples for javax.swing JLabel setBounds

Introduction

In this page you can find the example usage for javax.swing JLabel setBounds.

Prototype

public void setBounds(Rectangle r) 

Source Link

Document

Moves and resizes this component to conform to the new bounding rectangle r .

Usage

From source file:com.funambol.json.admin.JsonConnectorConfigPanel.java

/**
 * Create the panel/*w ww  .j a  va 2s .  c  o m*/
 */
private void init() {

    JLabel title, serverLabel;
    JPanel seccPanel;
    JPanel behaviourOnErrorsPanel;

    title = new JLabel();
    seccPanel = new JPanel();
    behaviourOnErrorsPanel = new JPanel();

    serverLabel = new JLabel();
    serverValue = new JTextField();

    setLayout(null);

    title.setFont(titlePanelFont);
    title.setText("Funambol Json Connector");
    title.setBounds(new Rectangle(14, 5, 316, 28));
    title.setAlignmentX(SwingConstants.CENTER);
    title.setBorder(new TitledBorder(""));

    seccPanel.setLayout(null);
    seccPanel.setBorder(new TitledBorder("HTTP Server Configuration"));

    serverLabel.setText("Server:");
    seccPanel.add(serverLabel);
    serverLabel.setBounds(10, 20, 116, 15);
    seccPanel.add(serverValue);
    serverValue.setBounds(150, 20, 220, 19);
    serverValue.setFont(defaultFont);

    add(seccPanel);
    seccPanel.setBounds(10, 50, 380, 70);

    //the ssl option panel

    behaviourOnErrorsPanel.setBorder(new TitledBorder("Behaviour on errors"));
    behaviourOnErrorsPanel.setLayout(null);

    stopSyncOnFatalError.setText("Stop sync on fatal errors");
    stopSyncOnFatalError.setBounds(10, 25, 200, 15);

    behaviourOnErrorsPanel.add(stopSyncOnFatalError);

    add(behaviourOnErrorsPanel);
    behaviourOnErrorsPanel.setBounds(10, 130, 380, 60);

    confirmButton.setFont(defaultFont);
    confirmButton.setText("Save");
    add(confirmButton);
    confirmButton.setBounds(160, 200, 70, 25);

    confirmButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                JsonConnectorConfigPanel.this.actionPerformed(new ActionEvent(JsonConnectorConfigPanel.this,
                        ACTION_EVENT_UPDATE, event.getActionCommand()));
            } catch (Exception e) {
                notifyError(new AdminException(e.getMessage()));
            }
        }
    });

    //
    // Setting font...
    //
    Component[] components = getComponents();
    for (int i = 0; (components != null) && (i < components.length); ++i) {
        components[i].setFont(defaultFont);
    }

    //
    // We add it as the last one so that the font won't be changed
    //
    add(title);
}

From source file:com.funambol.exchange.admin.DefaultExchangeConnectorConfigPanel.java

/**
 * Create the panel//from www  . j av a2s  .  c  o  m
 */
private void init() {

    JLabel title, contactFolderLabel, eventFolderLabel, taskFolderLabel, noteFolderLabel, seccServerLabel,
            seccPortLabel, exchangeServerLabel;
    JPanel seccPanel, exchangePanel, sslPanel;

    title = new JLabel();
    exchangePanel = new JPanel();
    seccPanel = new JPanel();
    sslPanel = new JPanel();

    contactFolderValue = new JTextField();
    eventFolderValue = new JTextField();
    taskFolderValue = new JTextField();
    noteFolderValue = new JTextField();
    seccServerLabel = new JLabel();
    seccServerValue = new JTextField();
    seccPortLabel = new JLabel();
    seccPortValue = new JTextField();
    useSSLValue = new JCheckBox();
    useFBAValue = new JCheckBox();
    useKeyStoreValue = new JCheckBox();
    keyStoreFileNameLabel = new JLabel();
    keyStoreFileNameValue = new JTextField();
    keyStorePasswordLabel = new JLabel();
    keyStorePasswordValue = new JTextField();

    exchangeServerLabel = new JLabel();
    exchangeServerValue = new JTextField();
    exchangeServerNameLabel = new JLabel();
    exchangeServerNameValue = new JTextField();
    setLayout(null);

    title.setFont(GuiFactory.titlePanelFont);
    title.setText("Funambol Exchange Connector");
    title.setBounds(new Rectangle(14, 5, 316, 28));
    title.setAlignmentX(SwingConstants.CENTER);
    title.setBorder(new TitledBorder(""));

    contactFolderLabel = new JLabel();
    contactFolderLabel.setText("Contact Folder: ");
    contactFolderLabel.setBounds(14, 35, 116, 15);
    add(contactFolderLabel);
    contactFolderValue.setBounds(150, 35, 220, 19);
    add(contactFolderValue);

    eventFolderLabel = new JLabel();
    eventFolderLabel.setText("Event Folder: ");
    eventFolderLabel.setBounds(14, 65, 116, 15);
    add(eventFolderLabel);
    eventFolderValue.setBounds(150, 65, 220, 19);
    add(eventFolderValue);

    taskFolderLabel = new JLabel();
    taskFolderLabel.setText("Task Folder: ");
    taskFolderLabel.setBounds(14, 95, 116, 15);
    add(taskFolderLabel);
    taskFolderValue.setBounds(150, 95, 220, 19);
    add(taskFolderValue);

    noteFolderLabel = new JLabel();
    noteFolderLabel.setText("Note Folder: ");
    noteFolderLabel.setBounds(14, 125, 116, 15);
    add(noteFolderLabel);
    noteFolderValue.setBounds(150, 125, 220, 19);
    add(noteFolderValue);

    seccPanel.setLayout(null);
    seccPanel.setBorder(new TitledBorder("HTTP Server Configuration"));

    seccServerLabel.setText("Server:");
    seccPanel.add(seccServerLabel);
    seccServerLabel.setBounds(10, 20, 116, 15);
    seccPanel.add(seccServerValue);
    seccServerValue.setBounds(150, 20, 220, 19);
    seccServerValue.setFont(GuiFactory.defaultFont);

    seccPortLabel.setText("Port:");
    seccPanel.add(seccPortLabel);
    seccPortLabel.setBounds(10, 50, 131, 15);
    seccPanel.add(seccPortValue);
    seccPortValue.setBounds(150, 50, 220, 19);
    seccPortValue.setFont(GuiFactory.defaultFont);

    add(seccPanel);
    seccPanel.setBounds(10, 155, 380, 80);

    exchangePanel.setLayout(null);
    exchangePanel.setBorder(new TitledBorder("WebDav Message Configuration"));

    exchangeServerLabel.setText("Server: ");
    exchangePanel.add(exchangeServerLabel);
    exchangeServerLabel.setBounds(10, 20, 150, 19);
    exchangePanel.add(exchangeServerValue);
    exchangeServerValue.setBounds(150, 20, 220, 19);
    exchangeServerValue.setFont(GuiFactory.defaultFont);

    exchangeServerNameLabel.setText("Name:");
    exchangeServerNameLabel.setBounds(10, 50, 150, 19);
    exchangePanel.add(exchangeServerNameLabel);
    exchangeServerNameValue.setBounds(150, 50, 220, 19);
    exchangeServerNameValue.setFont(GuiFactory.defaultFont);
    exchangePanel.add(exchangeServerNameValue);

    add(exchangePanel);
    exchangePanel.setBounds(10, 255, 380, 80);

    //the ssl option panel

    sslPanel.setLayout(null);
    sslPanel.setBorder(new TitledBorder("SSL"));

    useSSLValue.setText("Use SSL");
    useSSLValue.setSelected(false);
    useSSLValue.setBounds(5, 20, 150, 19);
    sslPanel.add(useSSLValue);

    useFBAValue.setText("Use Form-Based Authentication");
    useFBAValue.setSelected(true);
    useFBAValue.setBounds(5, 40, 250, 19);
    sslPanel.add(useFBAValue);

    useKeyStoreValue.setText("Use Keystore");
    useKeyStoreValue.setSelected(false);
    useKeyStoreValue.setBounds(5, 60, 200, 19);
    sslPanel.add(useKeyStoreValue);

    useKeyStoreValue.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent acEvent) {
            boolean enabled = useKeyStoreValue.isSelected();
            keyStoreFileNameLabel.setEnabled(enabled);
            keyStoreFileNameValue.setEnabled(enabled);
            keyStorePasswordLabel.setEnabled(enabled);
            keyStorePasswordValue.setEnabled(enabled);
        }
    });

    keyStoreFileNameLabel.setText("Key Store File: ");
    sslPanel.add(keyStoreFileNameLabel);
    keyStoreFileNameLabel.setEnabled(false);
    keyStoreFileNameLabel.setBounds(10, 80, 131, 15);
    sslPanel.add(keyStoreFileNameValue);
    keyStoreFileNameValue.setEnabled(false);
    keyStoreFileNameValue.setBounds(150, 80, 220, 19);
    keyStoreFileNameValue.setFont(GuiFactory.defaultFont);

    keyStorePasswordLabel.setText("Key Store Password: ");
    sslPanel.add(keyStorePasswordLabel);
    keyStorePasswordLabel.setEnabled(false);
    keyStorePasswordLabel.setBounds(10, 110, 131, 15);
    sslPanel.add(keyStorePasswordValue);
    keyStorePasswordValue.setEnabled(false);
    keyStorePasswordValue.setBounds(150, 110, 220, 19);
    keyStorePasswordValue.setFont(GuiFactory.defaultFont);

    add(sslPanel);
    sslPanel.setBounds(10, 355, 450, 140);

    confirmButton.setFont(GuiFactory.defaultFont);
    confirmButton.setText("Save");
    add(confirmButton);
    confirmButton.setBounds(120, 500, 70, 25);
    confirmButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            getValues();
            configPanel.saveDefaultConfig(event.getActionCommand());
            configPanel.finishedDefaultConfig();
        }
    });

    cancelButton.setFont(GuiFactory.defaultFont);
    cancelButton.setText("Cancel");
    add(cancelButton);
    cancelButton.setBounds(200, 500, 70, 25);
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            configPanel.finishedDefaultConfig();
        }

    });

    //
    // Setting font...
    //
    Component[] components = getComponents();
    for (int i = 0; (components != null) && (i < components.length); ++i) {
        components[i].setFont(GuiFactory.defaultFont);
    }

    //
    // We add it as the last one so that the font won't be changed
    //
    add(title);
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Includes the given image inside of the selected views. If a view is an `ImageView`, its image
 * is set. Otherwise, the background image of the view is set.
 * @param image the drawable image to include
 * @return this/*from w ww. ja  va 2 s .c om*/
 */
public $ image(Image image) {
    for (Component v : views) {
        if (v instanceof JLabel) {
            ((JLabel) v).setIcon(new ImageIcon(image));
        } else if (v instanceof Window) {
            ((Window) v).setIconImage(image);
        } else {
            if (v instanceof Container) {
                JLabel l = new JLabel(new ImageIcon(image));
                l.setBounds(v.getBounds());
                ((Container) v).add(l);
            } else if (v.getParent() != null && v.getParent() instanceof Container) {
                JLabel l = new JLabel(new ImageIcon(image));
                l.setBounds(v.getBounds());
                ((Container) v.getParent()).add(l);
            }

        }
    }
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * For `ImageView`s, this will set the image to the given asset or url. Otherwise, it will set the
 * background image for the selected views.
 * @param source asset path, file path (starting with "file://") or URL to image
 * @param width specifies the output bitmap width
 * @param height specifies the output bitmap height
 * @param error if the given source is a file or asset, this receives a javaQuery wrapping the 
 * current context and the {@code Throwable} error. Otherwise, this will receive an
 * Ajax error./*w w w. ja va  2s .  c  o  m*/
 * @return this
 * @see AjaxOptions#error(Function)
 */
public $ image(String source, int width, int height, Function error) {
    if (source.startsWith("file://")) {
        try {
            Image image = ImageIO.read(new File(source.substring(7)));

            for (Component v : views) {
                if (v instanceof JLabel) {
                    ((JLabel) v).setIcon(new ImageIcon(image));
                } else if (v instanceof Window) {
                    ((Window) v).setIconImage(image);
                } else {
                    if (v instanceof Container) {
                        JLabel l = new JLabel(new ImageIcon(image));
                        l.setBounds(v.getBounds());
                        ((Container) v).add(l);
                    } else if (v.getParent() != null && v.getParent() instanceof Container) {
                        JLabel l = new JLabel(new ImageIcon(image));
                        l.setBounds(v.getBounds());
                        ((Container) v.getParent()).add(l);
                    }

                }
            }
        } catch (Throwable t) {
            if (error != null) {
                error.invoke($.with(view(0)), t);
            }
        }
    } else {
        boolean fallthrough = false;
        try {
            new URL(source);
        } catch (Throwable t) {
            fallthrough = true;
        }
        if (fallthrough) {
            AjaxOptions options = new AjaxOptions().url(source).type("GET").dataType("image").context(view(0))
                    .global(false).success(new Function() {
                        @Override
                        public void invoke($ javaQuery, Object... params) {
                            Image image = (Image) params[0];
                            for (Component v : views) {
                                if (v instanceof JLabel) {
                                    ((JLabel) v).setIcon(new ImageIcon(image));
                                } else if (v instanceof Window) {
                                    ((Window) v).setIconImage(image);
                                } else {
                                    if (v instanceof Container) {
                                        JLabel l = new JLabel(new ImageIcon(image));
                                        l.setBounds(v.getBounds());
                                        ((Container) v).add(l);
                                    } else if (v.getParent() != null && v.getParent() instanceof Container) {
                                        JLabel l = new JLabel(new ImageIcon(image));
                                        l.setBounds(v.getBounds());
                                        ((Container) v.getParent()).add(l);
                                    }

                                }
                            }
                        }
                    });

            if (error != null) {
                options.error(error);
            }
            if (width >= 0) {
                options.imageWidth(width);
            }
            if (height >= 0) {
                options.imageHeight(height);
            }
            $.ajax(options);
        }
    }
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Include the html string the selected views. If a view has a setText method, it is used. Otherwise,
 * a new TextView is created. This html can also handle image tags for both urls and local files.
 * Local files should be the name (for example, for R.id.ic_launcher, just use ic_launcher).
 * @param html the HTML String to include
 *///  w  w w.  j  ava  2  s.c  o m
public $ html(String html) {
    for (Component view : this.views) {
        try {
            Method m = view.getClass().getMethod("setText", new Class<?>[] { String.class });
            m.invoke(view, html);
        } catch (Throwable t) {
            if (view instanceof Container) {
                try {
                    //no setText method. Try a TextView
                    JLabel label = new JLabel();
                    int rgba = Color.HSBtoRGB(0, 0, 0);
                    rgba |= (0 & 0xff);
                    label.setBackground(new Color(rgba, true));
                    label.setBounds(label.getParent().getBounds());
                    ((Container) view).add(label);
                    label.setText(html);
                } catch (Throwable t2) {
                    //unable to set content
                    Log.w("javaQuery", "unable to set HTML content");
                }
            } else {
                //unable to set content
                Log.w("javaQuery", "unable to set textual content");
            }
        }
    }

    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Includes the given text string inside of the selected views. If a view has a setText method, it is used
 * otherwise, if possible, a textview is added as a child to display the text.
 * @param text the text to include//from ww w  .  j a  va  2  s  . c  om
 */
public $ text(String text) {
    for (Component view : this.views) {
        try {
            Method m = view.getClass().getMethod("setText", new Class<?>[] { String.class });
            m.invoke(view, text);
        } catch (Throwable t) {
            if (view instanceof Container) {
                try {
                    //no setText method. Try a TextView
                    JLabel label = new JLabel();
                    int rgba = Color.HSBtoRGB(0, 0, 0);
                    rgba |= (0 & 0xff);
                    label.setBackground(new Color(rgba, true));
                    label.setBounds(label.getParent().getBounds());
                    ((Container) view).add(label);
                    label.setText(text);
                } catch (Throwable t2) {
                    //unable to set content
                    Log.w("javaQuery", "unable to set textual content");
                }
            } else {
                //unable to set content
                Log.w("javaQuery", "unable to set textual content");
            }
        }
    }

    return this;
}