📄 columnpopupmenu.java
字号:
/*
* 09/16/2004
*
* ColumnPopupMenu.java - A popup menu capable of having multiple columns of
* menu items.
* Copyright (C) 2004 Robert Futrell
* email@address.com
* www.website.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.fife.ui;
import java.awt.Component;
import java.awt.GridLayout;
import javax.swing.JPopupMenu;
/**
* FIXME: This class needs its own layout that behaves like a cross between
* GridLayout and BoxLayout(Y_AXIS). It currently uses GridLayout but
* that makes separators the same height as regular menu items!!
*/
public class ColumnPopupMenu extends JPopupMenu {
/**
*
*/
private static final long serialVersionUID = 1972419982380122049L;
private int desiredColumns;
/*****************************************************************************/
/**
* Constructor.
*
* @param desiredColumns The number of columns for this popup menu. Note
* that if the number of menu items is less than this value, then
* value, then the popup menu will only use enough columns for all of
* columns for all of the items (for appearances). A value of
* A value of <code>1</code> here makes the popup menu behave
* exactly like a regular popup menu.
*/
public ColumnPopupMenu(int desiredColumns) {
super();
this.desiredColumns = desiredColumns;
}
/*****************************************************************************/
/**
* Sets up the layout properly, depending on the number of items in the
* popup menu. You only need to call this once, after all items have been
* added to the popup menu. If you add or remove any items, you should
* recall this method.
*/
public void redoLayout() {
Component[] comps = getComponents();
int numComponents = comps.length;
removeAll();
if (numComponents<desiredColumns)
setLayout(new GridLayout(1, numComponents));
else {
int columnCount = desiredColumns;
int rowCount = numComponents/columnCount;
if ((numComponents%columnCount)!=0)
rowCount++;
setLayout(new GridLayout(rowCount, columnCount));
}
for (int i=0; i<comps.length; i++)
add(comps[i]);
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -