当前位置: 技术问答>java相关
Menu problem
来源: 互联网 发布时间:2015-06-29
本文导语: Now I would like to create a menu contains more childern that a window can handle (say 1000), is there anyway for me to scroll throught the menu? Or possible to add something like combo in the menu? Or is there any other create ideas to han...
Now I would like to create a menu contains more childern that a window can handle (say 1000), is there anyway for me to scroll throught the menu?
Or possible to add something like combo in the menu? Or is there any other create ideas to handle that?
Or possible to add something like combo in the menu? Or is there any other create ideas to handle that?
|
/*http://forum.java.sun.com/thread.jsp?forum=57&thread=123183
Re: scrollable JMenu?
Author: frankm29
In Reply To: scrollable JMenu? Apr 30, 2002 6:35 PM
Reply 4 of 5
Here's a cl*** I made to make JMenu scrollable, use it if it can help you...
Frank
*/
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
// This cl*** implements a scrollable JMenu
// This cl*** was hacked out in a couple of hours, and is meant to be used
// such that you create an instance, add all the items you want, and then throw it away and
// create a new one if you want the menu items to change (there is no remove/insertAt functionality)
// Use "addScrollableItems(JMenuItem j)" to add all of the items
// You can change MAX_ITEMS_TO_DISPLAY to whatever you want, I used 10 because it seems to always fit on screen
// I have NOT tested this cl*** very much to see if it loses items, etc, ***USE AT YOUR OWN RISK***
// Feel free to use and modify. I'll probably add a thread on the up & down scrollers to make them scroll automatically (as long as mouse-over),
// let me know if you want it via email (frank.mccreedy@nrlssc.navy.mil).
//
// This cl*** should only be used until SUN makes a real scrollable JMenu
public cl*** ScrollableJMenu extends JMenu implements MouseListener{
ScrollUpOrDownButtonItem scrollUp, scrollDown;
Vector vtrScrollableMenuItems;
static final int MAX_ITEMS_TO_DISPLAY = 10;
int beginIndexIntoVector;
public ScrollableJMenu(String strMenuTitle){
setText(strMenuTitle);
scrollUp = new ScrollUpOrDownButtonItem("up");
add(scrollUp);
removeAllMouseListeners(scrollUp);
scrollUp.addMouseListener(this);
scrollUp.addMouseListener(scrollUp);
scrollDown = new ScrollUpOrDownButtonItem("down");
add(scrollDown);
removeAllMouseListeners(scrollDown);
scrollDown.addMouseListener(this);
scrollDown.addMouseListener(scrollDown);
vtrScrollableMenuItems = new Vector();
beginIndexIntoVector = 0;
}
public void addScrollableItem(JMenuItem jmiMenuItemToAdd){
vtrScrollableMenuItems.addElement(jmiMenuItemToAdd);
if ( vtrScrollableMenuItems.size()
Re: scrollable JMenu?
Author: frankm29
In Reply To: scrollable JMenu? Apr 30, 2002 6:35 PM
Reply 4 of 5
Here's a cl*** I made to make JMenu scrollable, use it if it can help you...
Frank
*/
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
// This cl*** implements a scrollable JMenu
// This cl*** was hacked out in a couple of hours, and is meant to be used
// such that you create an instance, add all the items you want, and then throw it away and
// create a new one if you want the menu items to change (there is no remove/insertAt functionality)
// Use "addScrollableItems(JMenuItem j)" to add all of the items
// You can change MAX_ITEMS_TO_DISPLAY to whatever you want, I used 10 because it seems to always fit on screen
// I have NOT tested this cl*** very much to see if it loses items, etc, ***USE AT YOUR OWN RISK***
// Feel free to use and modify. I'll probably add a thread on the up & down scrollers to make them scroll automatically (as long as mouse-over),
// let me know if you want it via email (frank.mccreedy@nrlssc.navy.mil).
//
// This cl*** should only be used until SUN makes a real scrollable JMenu
public cl*** ScrollableJMenu extends JMenu implements MouseListener{
ScrollUpOrDownButtonItem scrollUp, scrollDown;
Vector vtrScrollableMenuItems;
static final int MAX_ITEMS_TO_DISPLAY = 10;
int beginIndexIntoVector;
public ScrollableJMenu(String strMenuTitle){
setText(strMenuTitle);
scrollUp = new ScrollUpOrDownButtonItem("up");
add(scrollUp);
removeAllMouseListeners(scrollUp);
scrollUp.addMouseListener(this);
scrollUp.addMouseListener(scrollUp);
scrollDown = new ScrollUpOrDownButtonItem("down");
add(scrollDown);
removeAllMouseListeners(scrollDown);
scrollDown.addMouseListener(this);
scrollDown.addMouseListener(scrollDown);
vtrScrollableMenuItems = new Vector();
beginIndexIntoVector = 0;
}
public void addScrollableItem(JMenuItem jmiMenuItemToAdd){
vtrScrollableMenuItems.addElement(jmiMenuItemToAdd);
if ( vtrScrollableMenuItems.size()
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!