本文整理汇总了Java中javax.swing.JLabel.setComponentPopupMenu方法的典型用法代码示例。如果您正苦于以下问题:Java JLabel.setComponentPopupMenu方法的具体用法?Java JLabel.setComponentPopupMenu怎么用?Java JLabel.setComponentPopupMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JLabel
的用法示例。
在下文中一共展示了JLabel.setComponentPopupMenu方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initReferenceLabel
import javax.swing.JLabel; //导入方法依赖的package包/类
private void initReferenceLabel() {
imageChooser.setFileFilter(new FileNameExtensionFilter("Image", "jpg", "png", "gif", "bmp"));
referenceLabel = new JLabel() {
@Override
public void paint(Graphics grphcs) {
super.paint(grphcs);
paintPage(grphcs);
}
};
referenceLabel.setHorizontalAlignment(SwingConstants.CENTER);
referenceLabel.setComponentPopupMenu(referencePopup);
jScrollPane2.setViewportView(referenceLabel);
offsetAdapter = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
setOffsetMarker(e);
}
};
referenceLabel.addMouseListener(offsetAdapter);
}
示例2: getContainerPanel
import javax.swing.JLabel; //导入方法依赖的package包/类
private JPanel getContainerPanel() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
label = new JLabel("Test Label");
JPopupMenu popup = new JPopupMenu();
JMenuItem menuItem1 = new JMenuItem("Item 1");
JMenuItem menuItem2 = new JMenuItem("Item 2");
JMenuItem menuItem3 = new JMenuItem("Item 3");
JMenuItem menuItem4 = new JMenuItem("Item 4");
JMenuItem menuItem5 = new JMenuItem("Item 5");
menuItem1.setOpaque(false);
menuItem2.setOpaque(false);
menuItem3.setOpaque(false);
menuItem4.setOpaque(false);
menuItem5.setOpaque(false);
popup.add(menuItem1);
popup.add(menuItem2);
popup.add(menuItem3);
popup.add(menuItem4);
popup.add(menuItem5);
label.setComponentPopupMenu(popup);
popup.setBackground(Color.CYAN);
panel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
panel.setBackground(Color.CYAN);
return panel;
}