Example usage for javax.swing JPanel setPreferredSize

List of usage examples for javax.swing JPanel setPreferredSize

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:savant.plugin.builtin.SAFEBrowser.java

public final Component getCenterPanel(List<TreeBrowserEntry> roots) {
    table = new TreeTable(new TreeBrowserModel(roots) {
        @Override//  w  ww .j a  v  a2 s. com
        public String[] getColumnNames() {
            return new String[] { "Name", "Description" };
        }

    });
    table.setSortable(false);
    table.setRespectRenderPreferredHeight(true);

    // configure the TreeTable
    table.setExpandAllAllowed(true);
    table.setShowTreeLines(false);
    table.setSortingEnabled(false);
    table.setRowHeight(18);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.expandFirstLevel();
    table.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                actOnSelectedItem(true);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });

    // do not select row when expanding a row.
    table.setSelectRowWhenToggling(false);

    table.getColumnModel().getColumn(0).setPreferredWidth(200);
    //table.getColumnModel().getColumn(1).setPreferredWidth(400);
    //table.getColumnModel().getColumn(2).setPreferredWidth(100);
    //table.getColumnModel().getColumn(3).setPreferredWidth(100);
    //table.getColumnModel().getColumn(4).setPreferredWidth(50);

    table.getColumnModel().getColumn(0).setCellRenderer(FILE_RENDERER);

    // add searchable feature
    TableSearchable searchable = new TableSearchable(table) {

        @Override
        protected String convertElementToString(Object item) {
            if (item instanceof TreeBrowserEntry) {
                return ((TreeBrowserEntry) item).getType();
            }
            return super.convertElementToString(item);
        }
    };
    searchable.setMainIndex(0); // only search for name column

    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.getViewport().setBackground(Color.WHITE);

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(800, 500));
    return panel;
}

From source file:savant.plugin.builtin.SavantFileRepositoryBrowser.java

public final Component getCenterPanel(List<TreeBrowserEntry> roots) {
    table = new TreeTable(new TreeBrowserModel(roots) {
        @Override// www  .ja va2s.com
        public String[] getColumnNames() {
            return new String[] { "Name", "Description" };
        }
    });
    table.setSortable(true);
    table.setRespectRenderPreferredHeight(true);

    // configure the TreeTable
    table.setExpandAllAllowed(true);
    table.setShowTreeLines(false);
    table.setSortingEnabled(false);
    table.setRowHeight(18);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.expandFirstLevel();
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                actOnSelectedItem(true);
            }
        }
    });

    // do not select row when expanding a row.
    table.setSelectRowWhenToggling(false);

    table.getColumnModel().getColumn(0).setPreferredWidth(200);
    //table.getColumnModel().getColumn(1).setPreferredWidth(400);
    //table.getColumnModel().getColumn(2).setPreferredWidth(100);
    //table.getColumnModel().getColumn(3).setPreferredWidth(100);
    //table.getColumnModel().getColumn(4).setPreferredWidth(50);

    table.getColumnModel().getColumn(0).setCellRenderer(FILE_RENDERER);

    // add searchable feature
    TableSearchable searchable = new TableSearchable(table) {

        @Override
        protected String convertElementToString(Object item) {
            if (item instanceof TreeBrowserEntry) {
                return ((TreeBrowserEntry) item).getType();
            }
            return super.convertElementToString(item);
        }
    };
    searchable.setMainIndex(0); // only search for name column

    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.getViewport().setBackground(Color.WHITE);

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(800, 500));
    return panel;
}

From source file:savant.view.dialog.PluginRepositoryDialog.java

public final Component getCenterPanel(List<TreeBrowserEntry> roots) {
    table = new TreeTable(new TreeBrowserModel(roots) {
        @Override/*from   w  w w  .  j a va 2 s . com*/
        public String[] getColumnNames() {
            return new String[] { "Name", "Description", "Web Site" };
        }

        @Override
        public CellStyle getCellStyleAt(int rowIndex, int columnIndex) {
            return null;
        }
    });
    table.setSortable(true);
    table.setRespectRenderPreferredHeight(true);

    // configure the TreeTable
    table.setExpandAllAllowed(true);
    table.setShowTreeLines(false);
    table.setSortingEnabled(false);
    table.setRowHeight(18);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //table.expandAll();
    table.expandFirstLevel();
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int col = table.columnAtPoint(e.getPoint());
            if (col == 2) {
                Object o = table.getModel().getValueAt(table.rowAtPoint(e.getPoint()), col);
                if (o != null && (o instanceof URL)) {
                    System.out.println(o.toString());
                    try {
                        Desktop.getDesktop().browse(((URL) o).toURI());
                    } catch (Exception x) {
                        LOG.error("Unable to open link for " + o, x);
                    }
                    return;
                }
            }
            if (e.getClickCount() == 2) {
                downloadSelectedItem(true);
            }
        }
    });

    // do not select row when expanding a row.
    table.setSelectRowWhenToggling(false);

    table.getColumnModel().getColumn(0).setPreferredWidth(200);
    table.getColumnModel().getColumn(1).setPreferredWidth(520);
    table.getColumnModel().getColumn(2).setPreferredWidth(80);

    table.getColumnModel().getColumn(0).setCellRenderer(new FileRowCellRenderer());
    table.getColumnModel().getColumn(2).setCellRenderer(new WebLinkRenderer());

    // add searchable feature
    TableSearchable searchable = new TableSearchable(table) {

        @Override
        protected String convertElementToString(Object item) {
            if (item instanceof TreeBrowserEntry) {
                return ((TreeBrowserEntry) item).getType();
            }
            return super.convertElementToString(item);
        }
    };
    searchable.setMainIndex(0); // only search for name column

    JScrollPane scrollPane = new JScrollPane(table);

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(800, 500));
    return panel;
}

From source file:tufts.vue.AnalyzerAction.java

public void act(LWComponent c) {

    //if (VUE.getDRBrowser().getDataSourceViewer().mMapBasedSearchThreads.size() > 0)
    //{      /*from   www  .ja  va 2s  .  com*/
    //System.out.println("SEARCH ALREADY RUNNING!!!!!!!!!!!");
    //   return;

    //}  

    //Set the wait cursor here clear it when there's no threads left in the mbs.
    GUI.activateWaitCursor();

    //figure out if anything is checked
    int selectionCount = DefaultQueryEditor.getSelectedRepositoryCount();
    if (selectionCount == 0) {

        final ShowAgainDialog sad = new ShowAgainDialog(VUE.getApplicationFrame(), "noResourceSelected",
                VueResources.local("noResourceSelected.title"), "OK", null);
        JPanel panel = new JPanel(new GridLayout(1, 1));
        String label = Util.formatLines(VueResources.local("noResourceSelected.message"), 30);
        JLabel vLabel = new JLabel(label);
        if (Util.isMacPlatform()) {
            panel.setPreferredSize(new Dimension(425, 25));
            panel.setSize(new Dimension(425, 25));
            panel.setMinimumSize(new Dimension(425, 25));
        } else {
            panel.setPreferredSize(new Dimension(425, 25));
        }
        panel.add(vLabel);
        sad.setContentPanel(panel);
        VueUtil.centerOnScreen(sad);
        if (sad.showAgain()) {
            sad.setVisible(true);

            sad.setVisible(false);
            sad.dispose();
            GUI.clearWaitCursor();
            return;
        }

    }
    //   List<AnalyzerResult> list = analyzer.analyze(c);
    //     Iterator<AnalyzerResult> i = list.iterator();
    VUE.getActiveViewer().getSelection().clear();
    //System.out.println("BLAH");
    boolean hasResults = false;
    String query = "";
    final int MAX_TERMS = 1;
    int termCount = 0;
    /*    while (i.hasNext() && termCount < MAX_TERMS)
        {      
           hasResults = true;
           AnalyzerResult l = i.next();
            
           if (l !=null && l.getValue() !=null)
           { //System.out.println(l.getRelevance() + " : " + l.getValue());
     query += l.getValue().trim() + " ";
     termCount++;
           }*/
    /*
     * MK - For testing purposes I was adding Nodes of the search terms to the map.
     *    if (l.getValue() !=null  && l.getValue().trim() != " " && !label.startsWith("Topic"))
       {
     LWNode node = new LWNode(label);
     VUE.getActiveMap().add(node);
     //VUE.getActiveViewer().getSelection().add(node);
     LWLink link = new LWLink(c,node);
     VUE.getActiveMap().add(link);
     VUE.getActiveViewer().getSelection().add(link);                  
     LayoutAction.random.act(VUE.getActiveViewer().getSelection());
       }*/
    //   }

    //if (query.equals(""))
    query = c.getLabel();
    //if (!hasResults)
    //{
    //   VueUtil.alert(VueResources.getString("dialog.analyzeerror.message"), VueResources.getString("dialog.analyzeerror.title"));

    //just use the label from the node, it didn't go right.
    //}

    VUE.getDRBrowser().getDataSourceViewer().queryEditor.setCriteria(query);
    VUE.getDRBrowser().getDataSourceViewer().mapBasedSearch(c);
    if (firstTime) {
        GUI.makeVisibleOnScreen(VUE.getDRBrowser());
        firstTime = false;
    }
    return;
}

From source file:VASSAL.launch.EditorWindow.java

protected EditorWindow() {
    setTitle("VASSAL " + getEditorType() + " Editor");
    setLayout(new BorderLayout());

    ApplicationIcons.setFor(this);

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            close();/* www .  j  a  va  2  s.com*/
        }
    });

    toolBar.setFloatable(false);
    add(toolBar, BorderLayout.NORTH);

    // setup menubar and actions
    final MenuManager mm = MenuManager.getInstance();
    final MenuBarProxy mb = mm.getMenuBarProxyFor(this);

    // file menu
    if (SystemUtils.IS_OS_MAC_OSX) {
        mm.addToSection("Editor.File", mm.addKey("Editor.save"));
        mm.addToSection("Editor.File", mm.addKey("Editor.save_as"));
    } else {
        final MenuProxy fileMenu = new MenuProxy(Resources.getString("General.file"));

        // FIMXE: setting nmemonic from first letter could cause collisions in
        // some languages
        fileMenu.setMnemonic(Resources.getString("General.file.shortcut").charAt(0));

        fileMenu.add(mm.addKey("Editor.save"));
        fileMenu.add(mm.addKey("Editor.save_as"));
        fileMenu.addSeparator();
        fileMenu.add(mm.addKey("General.quit"));
        mb.add(fileMenu);
    }

    // edit menu
    final MenuProxy editMenu = new MenuProxy(Resources.getString("General.edit"));
    editMenu.setMnemonic(Resources.getString("General.edit.shortcut").charAt(0));

    editMenu.add(mm.addKey("Editor.cut"));
    editMenu.add(mm.addKey("Editor.copy"));
    editMenu.add(mm.addKey("Editor.paste"));
    editMenu.add(mm.addKey("Editor.move"));
    editMenu.addSeparator();
    editMenu.add(mm.addKey("Editor.ModuleEditor.properties"));
    editMenu.add(mm.addKey("Editor.ModuleEditor.translate"));

    // tools menu
    final MenuProxy toolsMenu = new MenuProxy(Resources.getString("General.tools"));
    toolsMenu.setMnemonic(Resources.getString("General.tools.shortcut").charAt(0));

    toolsMenu.add(mm.addKey("create_module_updater"));
    toolsMenu.add(mm.addKey("Editor.ModuleEditor.update_saved"));

    if (SystemUtils.IS_OS_MAC_OSX) {
        mm.addToSection("Editor.MenuBar", editMenu);
        mm.addToSection("Editor.MenuBar", toolsMenu);
    } else {
        mb.add(editMenu);
        mb.add(toolsMenu);
    }

    // help menu
    if (SystemUtils.IS_OS_MAC_OSX) {
        mm.addToSection("Documentation.VASSAL", mm.addKey("Editor.ModuleEditor.reference_manual"));
    } else {
        final MenuProxy helpMenu = new MenuProxy(Resources.getString("General.help"));

        // FIMXE: setting nmemonic from first letter could cause collisions in
        // some languages
        helpMenu.setMnemonic(Resources.getString("General.help.shortcut").charAt(0));

        helpMenu.add(mm.addKey("General.help"));
        helpMenu.add(mm.addKey("Editor.ModuleEditor.reference_manual"));
        helpMenu.addSeparator();
        helpMenu.add(mm.addKey("AboutScreen.about_vassal"));
        mb.add(helpMenu);
    }

    final int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    saveAction = new SaveAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            save();
            treeStateChanged(false);
        }
    };

    saveAction.setEnabled(false);
    saveAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, mask));
    mm.addAction("Editor.save", saveAction);
    toolBar.add(saveAction);

    saveAsAction = new SaveAsAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            saveAs();
            treeStateChanged(false);
        }
    };

    saveAsAction.setEnabled(false);
    saveAsAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, mask));
    mm.addAction("Editor.save_as", saveAsAction);
    toolBar.add(saveAsAction);

    mm.addAction("General.quit", new ShutDownAction());
    // FXIME: mnemonics should be language-dependant
    //    mm.getAction("General.quit").setMnemonic('Q');

    createUpdater = new AbstractAction("Create " + getEditorType() + " updater") {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            new ModuleUpdaterDialog(EditorWindow.this).setVisible(true);
        }
    };
    createUpdater.setEnabled(false);
    mm.addAction("create_module_updater", createUpdater);

    URL url = null;
    try {
        url = new File(Documentation.getDocumentationBaseDir(), "README.html").toURI().toURL();
    } catch (MalformedURLException e) {
        ErrorDialog.bug(e);
    }
    mm.addAction("General.help", new ShowHelpAction(url, null));

    url = null;
    try {
        File dir = VASSAL.build.module.Documentation.getDocumentationBaseDir();
        dir = new File(dir, "ReferenceManual/index.htm"); //$NON-NLS-1$
        url = URLUtils.toURL(dir);
    } catch (MalformedURLException e) {
        ErrorDialog.bug(e);
    }

    final Action helpAction = new ShowHelpAction(url, helpWindow.getClass().getResource("/images/Help16.gif")); //$NON-NLS-1$
    helpAction.putValue(Action.SHORT_DESCRIPTION, Resources.getString("Editor.ModuleEditor.reference_manual")); //$NON-NLS-1$

    mm.addAction("Editor.ModuleEditor.reference_manual", helpAction);
    toolBar.add(helpAction);

    mm.addAction("AboutScreen.about_vassal", new AboutVASSALAction(this));

    setJMenuBar(mm.getMenuBarFor(this));

    // the presence of the panel prevents a NullPointerException on packing
    final JPanel panel = new JPanel();
    panel.setPreferredSize(new Dimension(250, 400));

    scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    add(scrollPane, BorderLayout.CENTER);
    pack();
}