Example usage for javax.swing JPanel getBorder

List of usage examples for javax.swing JPanel getBorder

Introduction

In this page you can find the example usage for javax.swing JPanel getBorder.

Prototype

public Border getBorder() 

Source Link

Document

Returns the border of this component or null if no border is currently set.

Usage

From source file:Main.java

public static void setFont(JComponent component, Font font, ComponentOrientation componentOrientation) {
    component.setFont(font);// w ww.  j a va  2 s .co m

    if (component instanceof JTextField) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JTextArea) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JTextPane) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JScrollPane) {
        for (Component cmp : component.getComponents()) {
            setFont((JComponent) cmp, font, componentOrientation);
        }
    }

    if (component instanceof JTree) {
        component.setComponentOrientation(componentOrientation);
    }

    if (component instanceof JComboBox) {
        component.setComponentOrientation(componentOrientation);
        JComboBox comboBox = (JComboBox) component;
        ((BasicComboBoxRenderer) comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.RIGHT);
        ((BasicComboBoxRenderer) comboBox.getRenderer()).setAutoscrolls(true);
        comboBox.setMaximumRowCount(20);
    }

    /* if(component instanceof JLabel) {
     ((JLabel)component).setHorizontalTextPosition(SwingConstants.RIGHT);
     }*/

    if (component instanceof JPanel) {
        JPanel panel = (JPanel) component;
        if (panel.getBorder() != null && panel.getBorder() instanceof TitledBorder) {
            ((TitledBorder) panel.getBorder()).setTitleFont(font);
            panel.setComponentOrientation(componentOrientation);
        }
        for (Component cmp : component.getComponents()) {
            setFont((JComponent) cmp, font, componentOrientation);
        }
    }

    if (component instanceof JTabbedPane) {
        JTabbedPane tabbedPane = (JTabbedPane) component;
        int tabCount = tabbedPane.getTabCount();
        for (int i = 0; i < tabCount; i++) {
            setFont((JComponent) tabbedPane.getComponentAt(i), font, componentOrientation);
        }
    }
}

From source file:be.ac.ua.comp.scarletnebula.gui.SSHPanel.java

public SSHPanel(final Server server) {
    super();/*from ww w  . j a v  a  2 s  . c o  m*/

    final JCTermSwing term = new JCTermSwing();
    term.setCompression(7);
    term.setAntiAliasing(true);

    setLayout(new BorderLayout());

    addComponentListener(new ComponentListener() {

        @Override
        public void componentShown(final ComponentEvent e) {
        }

        @Override
        public void componentResized(final ComponentEvent e) {
            final Component c = e.getComponent();
            int cw = c.getWidth();
            int ch = c.getHeight();

            final JPanel source = ((JPanel) c);

            final int cwm = source.getBorder() != null
                    ? source.getBorder().getBorderInsets(c).left + source.getBorder().getBorderInsets(c).right
                    : 0;
            final int chm = source.getBorder() != null
                    ? source.getBorder().getBorderInsets(c).bottom + source.getBorder().getBorderInsets(c).top
                    : 0;
            cw -= cwm;
            ch -= chm;

            term.setBorder(BorderFactory.createMatteBorder(0, 0, term.getTermHeight() - c.getHeight(),
                    term.getTermWidth() - c.getWidth(), Color.BLACK));
            term.setSize(cw, ch);
            term.setPreferredSize(new Dimension(cw, ch));
            // term.setMinimumSize(new Dimension(cw, ch));
            term.setMaximumSize(new Dimension(cw, ch));
            term.redraw(0, 0, term.getTermWidth(), term.getTermHeight());
        }

        @Override
        public void componentMoved(final ComponentEvent e) { // TODO
            // Auto-generated
            // method
            // stub

        }

        @Override
        public void componentHidden(final ComponentEvent e) { // TODO
            // Auto-generated
            // method
            // stub

        }
    });

    add(term, BorderLayout.CENTER);

    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20),
            BorderFactory.createBevelBorder(BevelBorder.LOWERED)));

    final Thread connectionThread = new Thread() {
        @Override
        public void run() {

            Connection connection = null;
            try {
                final SSHCommandConnection commandConnection = (SSHCommandConnection) server
                        .newCommandConnection(new NotPromptingJschUserInfo());

                connection = commandConnection.getJSchTerminalConnection();

                term.requestFocusInWindow();
                term.start(connection);
            } catch (final Exception e) {
                for (final ExceptionListener listener : exceptionListeners) {
                    listener.exceptionThrown(e);
                }

                log.warn("Exception thrown by SSHPanel", e);
            } finally {
            }

        }
    };

    connectionThread.start();
}

From source file:ome.formats.importer.gui.FileQueueChooser.java

/**
 * File chooser on the file picker tab of the importer
 * //from  w  w w .  j a  v  a 2s  . co  m
 * @param config ImportConfig
 * @param scanReader OmeroWrapper
 */
FileQueueChooser(ImportConfig config, OMEROWrapper scanReader) {

    try {
        JPanel fp = null;
        JToolBar tb = null;

        String refreshIcon = "gfx/recycled12.png";
        refreshBtn = GuiCommonElements.addBasicButton("Refresh ", refreshIcon, null);
        refreshBtn.setActionCommand(REFRESHED);
        refreshBtn.addActionListener(this);
        JPanel panel = new JPanel();

        // Set up the main panel for tPane, quit, and send buttons
        double mainTable[][] = { { 10, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, 10 }, // columns
                { TableLayout.PREFERRED } }; // rows

        TableLayout tl = new TableLayout(mainTable);
        panel.setLayout(tl);

        // Here's a nice little pieces of test code to find all components
        if (DEBUG) {
            try {
                Component[] components = this.getComponents();
                Component component = null;
                System.err.println("Components: " + components.length);
                for (int i = 0; i < components.length; i++) {
                    component = components[i];
                    System.err.println("Component " + i + " = " + component.getClass());
                }
            } catch (Exception e) {
                log.info("component exception ignore");
            }
        }

        if (laf.contains("AquaLookAndFeel")) {
            //Do Aqua implimentation
            fp = (JPanel) this.getComponent(1);
            fp.setLayout(new BoxLayout(fp, BoxLayout.X_AXIS));
            fp.add(refreshBtn);
        } else if (laf.contains("QuaquaLookAndFeel")) {
            //do Quaqua implimentation
            fp = (JPanel) this.getComponent(1);
            panel.add(refreshBtn, "1,0,C,C");
            panel.add(fp.getComponent(0), "2,0,C,C");
            fp.add(panel, BorderLayout.NORTH);
        } else if (laf.contains("Windows")) {
            try {
                //Do windows implimentation
                tb = (JToolBar) this.getComponent(1);
                refreshBtn.setToolTipText("Refresh");
                refreshBtn.setText(null);
                tb.add(refreshBtn, 8);
            } catch (Exception e) {
                log.info("Exception ignored.");
            }
        }
        /* Disabled temporarily */
        else if (laf.contains("MetalLookAndFeel")) {
            //Do Metal implimentation
            JPanel prefp = (JPanel) this.getComponent(0);
            fp = (JPanel) prefp.getComponent(0);
            refreshBtn.setToolTipText("Refresh");
            refreshBtn.setText(null);
            Dimension size = new Dimension(24, 24);
            refreshBtn.setMaximumSize(size);
            refreshBtn.setPreferredSize(size);
            refreshBtn.setMinimumSize(size);
            refreshBtn.setSize(size);
            fp.add(Box.createRigidArea(new Dimension(5, 0)));
            fp.add(refreshBtn);
        }

        else if (laf.contains("GTKLookAndFeel")) {
            //do GTK implimentation
            fp = (JPanel) this.getComponent(0);
            refreshBtn.setIcon(null);
            fp.add(refreshBtn);
        } else if (laf.contains("MotifLookAndFeel")) {
            //do Motif implimentation
            fp = (JPanel) this.getComponent(0);
            fp.add(refreshBtn);
        }

        if (fp != null && DEBUG == true) {
            fp.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                    fp.getBorder()));
            System.err.println(fp.getLayout());
        }

        if (tb != null && DEBUG == true) {
            tb.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                    tb.getBorder()));
            System.err.println(tb.getLayout());
        }
    } catch (ArrayIndexOutOfBoundsException e) {
    }

    File dir = null;
    if (config != null)
        dir = config.savedDirectory.get();

    if (dir != null) {
        this.setCurrentDirectory(dir);
    } else {
        this.setCurrentDirectory(this.getFileSystemView().getHomeDirectory());
    }

    this.setControlButtonsAreShown(false);
    this.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    this.setMultiSelectionEnabled(true);
    this.setDragEnabled(true);

    setAcceptAllFileFilterUsed(false);

    FileFilter[] originalFF = null;
    int readerFFSize = 0;
    if (scanReader != null) {
        originalFF = loci.formats.gui.GUITools.buildFileFilters(scanReader.getImageReader());
        FileFilter filter;
        List<FileFilter> extensionFilters = new ArrayList<FileFilter>();
        for (int i = 0; i < originalFF.length; i++) {
            filter = originalFF[i];
            if (filter instanceof ComboFileFilter) {
                ComboFileFilter cff = (ComboFileFilter) filter;
                extensionFilters.add(cff);
                extensionFilters.addAll(Arrays.asList(cff.getFilters()));
                break;
            }
        }
        if (extensionFilters != null) {
            originalFF = extensionFilters.toArray(new FileFilter[extensionFilters.size()]);
        }
        readerFFSize = originalFF.length;
    }

    FileFilter[] ff = new FileFilter[readerFFSize + 7];
    ff[0] = new DashFileFilter();
    ff[readerFFSize + 1] = new DashFileFilter();
    ff[readerFFSize + 2] = new R3DNewFileFilter();
    ff[readerFFSize + 3] = new R3DOldFileFilter();
    ff[readerFFSize + 4] = new D3DNewFileFilter();
    ff[readerFFSize + 5] = new D3DOldFileFilter();
    ff[readerFFSize + 6] = new D3DNPrjFileFilter();

    if (originalFF != null)
        System.arraycopy(originalFF, 0, ff, 1, originalFF.length);

    //this.addChoosableFileFilter(new DashFileFilter());

    //FileFilter combo = null;
    for (int i = 0; i < ff.length; i++)
        this.addChoosableFileFilter(ff[i]);
    this.setFileFilter(ff[1]);

    //Retrieve all JLists and JTables from the fileChooser
    fileListObjects = getFileListObjects(this);

    //For now, assume the first list/table found is the correct one
    //(this will need to be adjusted if LAF bugs crop up)
    //Shouldn't break anything since dblclick will just stop working if
    //this changes for some reason
    if (fileListObjects.length > 0 && !laf.contains("Windows")) {
        fileList = fileListObjects[0];
        MouseCommand mc = new MouseCommand();
        fileList.addMouseListener(mc);
    }
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a 'main panel' to a Frame or other container
 * //  w ww  . j a  va2  s .  c  om
 * @param container - parent container
 * @param tableSize - TableLayout table array
 * @param margin_top - top margin
 * @param margin_left - left margin
 * @param margin_bottom - bottom margin
 * @param margin_right - right margin
 * @param debug - turn on/off red debug borders
 * @return new JPanel
 */
public static JPanel addMainPanel(Container container, double tableSize[][], int margin_top, int margin_left,
        int margin_bottom, int margin_right, boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    TableLayout layout = new TableLayout(tableSize);
    panel.setLayout(layout);
    panel.setBorder(BorderFactory.createEmptyBorder(margin_top, margin_left, margin_bottom, margin_right));

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    return panel;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a bordered 'sub-panel' with title to a container
 * //  w  w  w  . j  a v  a 2s .c o m
 * @param container - parent container
 * @param tableSize - TableLayout table array
 * @param name - panel name
 * @param debug - turn on/off red debug borders
 * @return new JPanel
 */
public static JPanel addBorderedPanel(Container container, double tableSize[][], String name, boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    TableLayout layout = new TableLayout(tableSize);
    panel.setLayout(layout);
    panel.setBorder(BorderFactory.createTitledBorder(name));

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    return panel;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a plane sub-panel to an existing container
 * /*from  www . j a  v  a 2s. c  om*/
 * @param container - parent container
 * @param tableSize - TableLayout table array
 * @param debug - turn on/off red debug borders
 * @return new JPanel
 */
public static JPanel addPlanePanel(Container container, double tableSize[][], boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    TableLayout layout = new TableLayout(tableSize);
    panel.setLayout(layout);
    panel.setBorder(BorderFactory.createEmptyBorder());

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    return panel;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a new Text Field/*from   w  w  w . j  av  a  2 s  .co  m*/
 * 
 * @param container - parent container
 * @param name - name of text field
 * @param initialValue - initial value of text field
 * @param mnemonic - mnemonic key
 * @param tooltip - tool tip for field
 * @param suffix - suffix text for field
 * @param labelWidth - label width 
 * @param placement - TableLayout placement
 * @param debug - turn on/off red debug borders
 * @return JTextField
 */
public static JTextField addTextField(Container container, String name, String initialValue, int mnemonic,
        String tooltip, String suffix, double labelWidth, String placement, boolean debug) {

    double[][] size = null;

    JPanel panel = new JPanel();
    panel.setOpaque(false);

    if (suffix.equals(""))
        size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } };
    else
        size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } };

    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JLabel label = new JLabel(name);
    label.setDisplayedMnemonic(mnemonic);
    JTextField result = new JTextField(20);
    label.setLabelFor(result);
    label.setOpaque(false);
    result.setToolTipText(tooltip);
    if (initialValue != null)
        result.setText(initialValue);

    panel.add(label, "0, 0, r, c");
    panel.add(result, "1, 0, f, c");

    if (suffix.length() != 0) {
        JLabel suffixLabel = new JLabel(" " + suffix);
        panel.add(suffixLabel, "2,0, l, c");
    }

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    container.add(panel, placement);
    return result;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a new Password Text Field/*from  w ww. j ava 2s .  co  m*/
 * 
 * @param container - parent container
 * @param name - name of text field
 * @param initialValue - initial value of text field
 * @param mnemonic - mnemonic key
 * @param tooltip - tool tip for field
 * @param suffix - suffix text for field
 * @param labelWidth - label width 
 * @param placement - TableLayout placement
 * @param debug - turn on/off red debug borders
 * @return JPasswordField
 */
public static JPasswordField addPasswordField(Container container, String name, String initialValue,
        int mnemonic, String tooltip, String suffix, double labelWidth, String placement, boolean debug) {

    double[][] size = null;

    JPanel panel = new JPanel();
    panel.setOpaque(false);

    if (suffix.equals(""))
        size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } };
    else
        size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } };

    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JLabel label = new JLabel(name);
    label.setDisplayedMnemonic(mnemonic);

    JPasswordField result = new JPasswordField(20);
    label.setLabelFor(result);
    label.setOpaque(false);
    result.setToolTipText(tooltip);
    if (initialValue != null)
        result.setText(initialValue);

    panel.add(label, "0, 0, r, c");
    panel.add(result, "1, 0, f, c");

    if (suffix.length() != 0) {
        JLabel suffixLabel = new JLabel(" " + suffix);
        panel.add(suffixLabel, "2,0, l, c");
    }

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    container.add(panel, placement);
    return result;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a TextArea that has scrolling functionality
 * //from w w  w.  j ava  2  s.c o m
 * @param container - parent container
 * @param name - name of text area
 * @param text - text to put in text area
 * @param mnemonic - mnemonic key
 * @param placement - TableLayout placement in parent container
 * @param debug - turn on/off red debug borders
 * @return JTextArea
 */
public static JTextArea addScrollingTextArea(Container container, String name, String text, int mnemonic,
        String placement, boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    double size[][] = { { TableLayout.FILL }, { 20, TableLayout.FILL } };
    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JTextArea textArea = new JTextArea();
    textArea.setLineWrap(true);
    textArea.setOpaque(true);

    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    if (!name.equals("")) {
        JLabel label = new JLabel(name);
        label.setOpaque(false);
        label.setDisplayedMnemonic(mnemonic);
        panel.add(label, "0, 0, l, c");
        panel.add(areaScrollPane, "0, 1, f, f");
    } else {
        panel.add(areaScrollPane, "0, 0, 0, 1");
    }

    container.add(panel, placement);

    return textArea;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add an image panel to the parent container
 * /*from  w  w w . j  a  v a 2  s.  c o m*/
 * @param container - parent container
 * @param imageString - string to use for imgURL
 * @param placement - TableLayout placement of panel within parent
 * @param debug - turn on/off red debug borders
 * @return image JPanel
 */
public static JPanel addImagePanel(JPanel container, String imageString, String placement, boolean debug) {
    ImageIcon icon = null;
    java.net.URL imgURL = GuiImporter.class.getResource(imageString);
    if (imgURL != null) {
        icon = new ImageIcon(imgURL);
    }
    JPanel panel = new ImagePanel(icon);

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));
    else
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.gray),
                panel.getBorder()));

    container.add(panel, placement);

    return panel;
}