本文整理汇总了Java中java.awt.event.MouseAdapter类的典型用法代码示例。如果您正苦于以下问题:Java MouseAdapter类的具体用法?Java MouseAdapter怎么用?Java MouseAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MouseAdapter类属于java.awt.event包,在下文中一共展示了MouseAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTree
import java.awt.event.MouseAdapter; //导入依赖的package包/类
/**
*
*/
private void buildTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("user");
tree = new JTree(root);
tree.putClientProperty("JTree.lineStyle", "Angled");
tree.setCellRenderer(new NavigationTreeCellRenderer());
tree.setShowsRootHandles(true);
DefaultTreeSelectionModel model = new DefaultTreeSelectionModel();
model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
graphsCategory = new DefaultMutableTreeNode("graphs");
mouseAdapter = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
itemSelected(e);
}
};
tree.addMouseListener(mouseAdapter);
root.add(graphsCategory);
loadGraphs();
}
示例2: WindowNotification
import java.awt.event.MouseAdapter; //导入依赖的package包/类
public WindowNotification() {
m_window = new JWindow();
m_window.setAlwaysOnTop(true);
m_listener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
fireListeners(CLICKED);
if (m_closeOnClick)
removeFromManager();
}
};
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setPanel(new JPanel());
}
示例3: prepareControls
import java.awt.event.MouseAdapter; //导入依赖的package包/类
@Override
protected void prepareControls() {
JDesktopPane desktopPane = new JDesktopPane();
JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false);
bottomFrame.setSize(220, 220);
super.propagateAWTControls(bottomFrame);
desktopPane.add(bottomFrame);
bottomFrame.setVisible(true);
JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false);
topFrame.setSize(200, 200);
topFrame.add(new JButton("LW Button") {
{
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
lwClicked = true;
}
});
}
});
desktopPane.add(topFrame);
topFrame.setVisible(true);
JFrame frame = new JFrame("Test Window");
frame.setSize(300, 300);
frame.setContentPane(desktopPane);
frame.setVisible(true);
locTopFrame = topFrame.getLocationOnScreen();
locTarget = new Point(locTopFrame.x + bottomFrame.getWidth() / 2, locTopFrame.y + bottomFrame.getHeight()/2);
}
示例4: ClassSelector
import java.awt.event.MouseAdapter; //导入依赖的package包/类
public ClassSelector(Comparator<ClassEntry> comparator) {
m_comparator = comparator;
// configure the tree control
setRootVisible(false);
setShowsRootHandles(false);
setModel(null);
// hook events
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
if (m_listener != null && event.getClickCount() == 2) {
// get the selected node
TreePath path = getSelectionPath();
if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) {
ClassSelectorClassNode node = (ClassSelectorClassNode)path.getLastPathComponent();
m_listener.onSelectClass(node.getClassEntry());
}
}
}
});
// init defaults
m_listener = null;
}
示例5: addMouseListenerToHeaderInTable
import java.awt.event.MouseAdapter; //导入依赖的package包/类
public void addMouseListenerToHeaderInTable(JTable table) {
final TableSorter sorter = this;
final JTable tableView = table;
tableView.setColumnSelectionAllowed(false);
MouseAdapter listMouseListener = new MouseAdapter() {
boolean ascending = false;
public void mouseClicked(MouseEvent e) {
TableColumnModel columnModel = tableView.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = tableView.convertColumnIndexToModel(viewColumn);
if (e.getClickCount() == 1 && column != -1) {
//System.out.println("Sorting ...");
//int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK;
//boolean ascending = (shiftPressed == 0);
if (column == sortBy)
ascending = !ascending;
else
ascending = true;
sorter.sortByColumn(column, ascending);
tableView.getTableHeader().updateUI();
}
}
};
JTableHeader th = tableView.getTableHeader();
th.addMouseListener(listMouseListener);
}
示例6: WhatIfPlot
import java.awt.event.MouseAdapter; //导入依赖的package包/类
public WhatIfPlot(double[] xAxis) {
super();
this.xAxis = xAxis;
// Adds popup menu
this.addMouseListener(new MouseAdapter() {
/**
* Invoked when the mouse has been clicked on a component.
*/
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
popup.show(WhatIfPlot.this, e.getX(), e.getY());
}
}
});
}
示例7: addChoice
import java.awt.event.MouseAdapter; //导入依赖的package包/类
public void addChoice(final String key, String displayText)
{
final JRadioButton rb = new JRadioButton(displayText);
if( doubleClickToSelect )
{
rb.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
if( e.getClickCount() >= 2 )
{
addClicked(key);
}
}
});
}
choices.addButton(rb, key);
// Add after the instructions label and any existing choices
add(rb, choices.size());
}
示例8: simpleFiller
import java.awt.event.MouseAdapter; //导入依赖的package包/类
private Box.Filler simpleFiller() {
Box.Filler filler = new Box.Filler(
new java.awt.Dimension(10, 0),
new java.awt.Dimension(10, 0),
new java.awt.Dimension(10, 32767));
filler.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent me) {
setGlassPane(docker);
SwingUtilities.invokeLater(() -> {
getGlassPane().setVisible(true);
});
}
});
return filler;
}
示例9: JCheckBoxList
import java.awt.event.MouseAdapter; //导入依赖的package包/类
public JCheckBoxList() {
setCellRenderer(new CellRenderer());
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int index = locationToIndex(e.getPoint());
if (index != -1) {
JCheckBox checkbox = getModel().getElementAt(index);
if (e.getPoint().x < checkbox.getHorizontalTextPosition()) {
checkbox.setSelected(!checkbox.isSelected());
}
repaint();
}
}
});
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
示例10: showModalDialog
import java.awt.event.MouseAdapter; //导入依赖的package包/类
private static void showModalDialog(Frame targetFrame) {
Dialog dialog = new Dialog(targetFrame, true);
dialog.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
passed = true;
dialog.dispose();
}
});
dialog.setSize(400, 300);
dialog.setTitle("Modal Dialog!");
clickOnModalDialog(dialog);
dialog.setVisible(true);
}
示例11: initialize
import java.awt.event.MouseAdapter; //导入依赖的package包/类
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 800, 450);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
final JButton btnNewButton = new JButton("\u62CD\u7167");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
flag = 1;// ��̬��������Ϊ1���Ӷ����°�ťʱ��ֹͣ����ͷ�ĵ���
}
});
btnNewButton.setBounds(33, 13, 113, 27);
frame.getContentPane().add(btnNewButton);
label = new JLabel("");
label.setBounds(0, 0, 800, 450);
frame.getContentPane().add(label);
}
示例12: buildList
import java.awt.event.MouseAdapter; //导入依赖的package包/类
/**
* Creates the process list
*
* @return JComponent
*/
private JComponent buildList() {
list = new JList<>();
list.setCellRenderer(new CellRenderer(list.getCellRenderer()));
list.setTransferHandler(new ProcessTransferHandler());
list.setDragEnabled(true);
list.setDropMode(DropMode.ON_OR_INSERT);
list.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() % 2 == 0) {
ProcessInformationPane.showDialog(list.getSelectedValue());
}
}
});
return ScrollFactory.pane(list).create();
}
示例13: BusyGlassPane
import java.awt.event.MouseAdapter; //导入依赖的package包/类
/**
* GlassPane constructor comment.
*
* @param Container a
*/
protected BusyGlassPane(Component activeComponent, boolean stopClosing)
{
this.stopClosing = stopClosing;
// add adapters that do nothing for keyboard and mouse actions
addMouseListener(new MouseAdapter()
{
// We don't care about any events
});
addKeyListener(new KeyAdapter()
{
// We don't care about any events
});
setActiveComponent(activeComponent);
}
示例14: initTestWindow
import java.awt.event.MouseAdapter; //导入依赖的package包/类
public static void initTestWindow() {
mainFrame = new Frame();
mainFrame.setTitle("TestWindow");
mainFrame.setBounds(700, 10, 300, 300);
mainFrame.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int ex = e.getModifiersEx();
if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) {
AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set.");
} else {
AltGraphModifierTest.pass();
}
}
});
mainFrame.setVisible(true);
}
示例15: HyperlinkLabel
import java.awt.event.MouseAdapter; //导入依赖的package包/类
/**
* Constructor
*/
public HyperlinkLabel() {
super();
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent evt) {
if (_url != null) {
Util.browse(_url, getText());
}
}
});
setForeground(Color.BLUE);
}