Example usage for javax.swing JMenuBar getPreferredSize

List of usage examples for javax.swing JMenuBar getPreferredSize

Introduction

In this page you can find the example usage for javax.swing JMenuBar getPreferredSize.

Prototype

@Transient
public Dimension getPreferredSize() 

Source Link

Document

If the preferredSize has been set to a non-null value just returns it.

Usage

From source file:SendMail.java

/**
 * Created by VisualCafe. Sets the window size.
 *///from   www  .  j a v  a  2s .  c o m
public void addNotify() {
    // Record the size of the window prior to
    // calling parents addNotify.
    Dimension size = getSize();

    super.addNotify();

    if (frameSizeAdjusted)
        return;
    frameSizeAdjusted = true;

    // Adjust size of frame according to the
    // insets and menu bar
    Insets insets = getInsets();
    javax.swing.JMenuBar menuBar = getRootPane().getJMenuBar();
    int menuBarHeight = 0;
    if (menuBar != null)
        menuBarHeight = menuBar.getPreferredSize().height;
    setSize(insets.left + insets.right + size.width, insets.top + insets.bottom + size.height + menuBarHeight);
}

From source file:com.qumasoft.guitools.compare.CompareFrame.java

@Override
public void addNotify() {
    // Record the size of the window prior to calling parents addNotify.
    Dimension size = getSize();/*from   w  w w.  ja  v a 2  s.  c o m*/

    super.addNotify();

    if (frameSizeAdjustedFlag) {
        return;
    }
    frameSizeAdjustedFlag = true;

    // Adjust size of frame according to the insets and menu bar
    Insets insets = getInsets();
    javax.swing.JMenuBar menuBar = getRootPane().getJMenuBar();
    int menuBarHeight = 0;
    if (menuBar != null) {
        menuBarHeight = menuBar.getPreferredSize().height;
    }
    setSize(insets.left + insets.right + size.width, insets.top + insets.bottom + size.height + menuBarHeight);
}

From source file:org.openconcerto.task.TodoListPanel.java

public TodoListPanel() {
    this.setOpaque(false);
    this.iconTache = new ImageIcon(TodoListPanel.class.getResource("tache.png"));
    this.iconPriorite = new ImageIcon(TodoListPanel.class.getResource("priorite.png"));
    this.userTableCellRenderer = new UserTableCellRenderer();
    this.timestampTableCellRendererCreated = new TimestampTableCellRenderer();
    this.timestampTableCellRendererDone = new TimestampTableCellRenderer();
    this.timestampTableCellRendererDeadLine = new TimestampTableCellRenderer(true);
    this.timestampTableCellEditorCreated = new TimestampTableCellEditor();
    this.timestampTableCellEditorDone = new TimestampTableCellEditor();
    this.timestampTableCellEditorDeadLine = new TimestampTableCellEditor();
    // Icon renderer
    List<URL> l = new Vector<URL>();
    l.add(TodoListPanel.class.getResource("empty.png"));
    l.add(TodoListPanel.class.getResource("high.png"));
    l.add(TodoListPanel.class.getResource("normal.png"));
    l.add(TodoListPanel.class.getResource("low.png"));
    this.iconEditor = new IconTableCellRenderer(l);
    this.iconRenderer = new IconTableCellRenderer(l);

    final User currentUser = UserManager.getInstance().getCurrentUser();
    this.model = new TodoListModel(currentUser);
    this.sorter = new TableSorter(this.model);
    this.t = new LightEventJTable(this.sorter) {
        public JToolTip createToolTip() {
            return new JMultiLineToolTip();
        }/* ww w.j a v  a 2 s  .  co m*/

        @Override
        public String getToolTipText(MouseEvent event) {
            String r = null;
            TodoListElement task = getTaskAt(event.getPoint());

            if (task != null && task.getCreatorId() > 1) {
                final String comment = task.getComment();
                if (comment != null) {
                    r = comment;
                    r += "\n\n";
                } else {
                    r = "";
                }
                r += getTM().trM("assignedBy", "user",
                        UserManager.getInstance().getUser(task.getCreatorId()).getFullName(), "date",
                        task.getDate());
            }

            return r;
        }

    };
    this.sorter.setTableHeader(this.t.getTableHeader());

    this.model.setTable(this.t);

    this.comboUser = new JMenu(TM.tr("showTaskAssignedTo"));
    initViewableUsers(currentUser);

    // L'utilisateur courant doit voir ses taches + toutes les taches dont il a les droits
    this.model.addIdListenerSilently(Integer.valueOf(currentUser.getId()));

    final int size = this.users.size();
    for (int i = 0; i < size; i++) {
        Integer id = Integer.valueOf((this.users.get(i)).getId());
        if (this.model.listenToId(id)) {
            ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(true);
        } else {
            ((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(false);
        }
    }

    this.addButton = new JButton(TM.tr("addTask"));
    this.removeButton = new JButton();
    this.removeButton.setOpaque(false);
    updateDeleteBtn();
    this.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 6;
    // SEP
    TitledSeparator sep = new TitledSeparator(
            currentUser.getFirstName() + " " + currentUser.getName().toUpperCase());
    this.add(sep, c);

    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy++;
    c.weightx = 0;
    this.add(this.addButton, c);
    c.gridx++;
    this.add(this.removeButton, c);

    c.anchor = GridBagConstraints.EAST;
    c.gridx++;
    final JMenuBar b = new JMenuBar();
    b.setOpaque(false);
    b.setBorderPainted(false);
    b.add(this.comboUser);
    // Pour que le menu ne disparaisse pas quand on rapetisse trop la fenetre en bas
    b.setMinimumSize(b.getPreferredSize());
    this.add(b, c);

    c.gridx++;
    c.weightx = 1;
    this.detailCheckBox = new JCheckBox(TM.tr("showDetails"));
    this.detailCheckBox.setOpaque(false);
    this.detailCheckBox.setSelected(false);
    this.add(this.detailCheckBox, c);

    //
    c.gridx++;
    this.hideOldCheckBox = new JCheckBox(TM.tr("hideHistory"));
    this.hideOldCheckBox.setOpaque(false);
    this.hideOldCheckBox.setSelected(true);
    this.add(this.hideOldCheckBox, c);

    c.gridx++;

    c.weightx = 0;
    c.anchor = GridBagConstraints.EAST;
    this.reloadPanel.setOpaque(false);
    this.add(this.reloadPanel, c);

    // Table
    c.gridwidth = 6;
    c.gridx = 0;
    c.gridy++;
    c.fill = GridBagConstraints.BOTH;
    c.weighty = 1;
    c.weightx = 1;
    initPopUp();
    initTable(TodoListModel.SIMPLE_MODE);
    this.add(new JScrollPane(this.t), c);

    initListeners();

    this.model.asynchronousFill();
}