use of javax.swing.JMenu in project jdk8u_jdk by JetBrains.
the class MisplacedBorder method run.
@Override
public void run() {
final JMenuBar menubar = new JMenuBar();
menubar.add(new JMenu(""));
menubar.add(new JMenu(""));
final JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setJMenuBar(menubar);
frame.setSize(W / 3, H / 3);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
// draw menu bar using standard order.
final BufferedImage bi1 = step1(menubar);
// draw menu border on top of the menu bar, nothing should be changed.
final BufferedImage bi2 = step2(menubar);
frame.dispose();
for (int x = 0; x < W; ++x) {
for (int y = 0; y < H; ++y) {
if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
try {
ImageIO.write(bi1, "png", new File("image1.png"));
ImageIO.write(bi2, "png", new File("image2.png"));
} catch (IOException e) {
e.printStackTrace();
}
throw new RuntimeException("Failed: wrong color");
}
}
}
}
use of javax.swing.JMenu in project jdk8u_jdk by JetBrains.
the class bug8071705 method runActualTest.
private static void runActualTest(GraphicsDevice device, CountDownLatch latch, JFrame frame, boolean[] result) {
Rectangle screenBounds = setLocation(frame, device);
JMenu menu = frame.getJMenuBar().getMenu(0);
menu.doClick();
Point location = menu.getLocationOnScreen();
JPopupMenu pm = menu.getPopupMenu();
Dimension pmSize = pm.getSize();
int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
int height = location.y + yOffset + pmSize.height + menu.getHeight();
int available = screenBounds.y + screenBounds.height - height;
if (available > 0) {
Point origin = pm.getLocationOnScreen();
if (origin.y < location.y) {
// growing upward, wrong!
result[0] = false;
} else {
// growing downward, ok!
result[0] = true;
}
} else {
// there is no space, growing upward would be ok, so we pass
result[0] = true;
}
}
use of javax.swing.JMenu in project DistributedFractalNetwork by Budder21.
the class Display method menus.
private JMenuBar menus() {
ToolTipManager.sharedInstance().setInitialDelay(0);
JMenuBar bar = new JMenuBar();
JMenu view = new JMenu("View");
JMenuItem serverLog = new JMenuItem("Server Log");
serverLog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame f = new JFrame("Server Log");
JTextArea textArea = new JTextArea(35, 55);
JScrollPane scroll = new JScrollPane(textArea);
textArea.setText(log.getLog());
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
f.setLayout(new BorderLayout());
f.add(scroll, BorderLayout.CENTER);
JButton b = new JButton("Save");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
fileChooser.setFileFilter(filter);
fileChooser.setCurrentDirectory(new File("fractals/logs"));
fileChooser.showSaveDialog(null);
String dir = fileChooser.getSelectedFile().getPath();
if (!dir.substring(dir.lastIndexOf(".") + 1).equals("txt"))
dir = dir.substring(0, dir.lastIndexOf(".")) + ".txt";
System.out.println("\n\n" + dir + "\n\n");
try {
PrintWriter out = new PrintWriter(dir);
Scanner s = new Scanner(textArea.getText());
while (s.hasNextLine()) out.println(s.nextLine());
out.flush();
out.close();
} catch (FileNotFoundException e1) {
log.addError(e1);
}
}
});
JPanel tempPanel = new JPanel();
tempPanel.add(b);
f.add(tempPanel, BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setResizable(true);
f.setVisible(true);
}
});
serverLog.setToolTipText("Displays the log of the current server.");
view.add(serverLog);
bar.add(view);
return bar;
}
use of javax.swing.JMenu in project pcgen by PCGen.
the class GMGenSystem method createEditMenu.
// Create the edit menu
private void createEditMenu() {
editMenu = new JMenu();
cutEditItem = new JMenuItem();
copyEditItem = new JMenuItem();
pasteEditItem = new JMenuItem();
editSeparator1 = new JSeparator();
preferencesEditItem = new JMenuItem();
// EDIT MENU
CommonMenuText.name(editMenu, PCGenActionMap.MNU_EDIT);
editMenu.addMenuListener(this);
CommonMenuText.name(cutEditItem, MNU_CUT);
editMenu.add(cutEditItem);
CommonMenuText.name(copyEditItem, MNU_COPY);
editMenu.add(copyEditItem);
CommonMenuText.name(pasteEditItem, MNU_PASTE);
editMenu.add(pasteEditItem);
// Preferences... on MAC OS X is in the application menu. See macOSXRegistration()
if (!SystemUtils.IS_OS_MAC_OSX) {
editMenu.add(editSeparator1);
CommonMenuText.name(preferencesEditItem, PCGenActionMap.MNU_TOOLS_PREFERENCES);
editMenu.add(preferencesEditItem);
preferencesEditItem.setEnabled(true);
ActionListener[] listenerArray = preferencesEditItem.getActionListeners();
for (final ActionListener aListenerArray : listenerArray) {
preferencesEditItem.removeActionListener(aListenerArray);
}
preferencesEditItem.addActionListener(this::mPreferencesActionPerformed);
}
systemMenuBar.add(editMenu);
}
use of javax.swing.JMenu in project pcgen by PCGen.
the class NotesPlugin method handleStateChangedMessage.
/**
* Handles the StateChangedMessage
*
* @param message StateChangedMessage
*/
private void handleStateChangedMessage(FocusOrStateChangeOccurredMessage message) {
if (isActive()) {
notesToolsItem.setEnabled(false);
JMenu editMenu = message.getEditMenu();
if (editMenu != null) {
theView.initEditMenu(editMenu);
}
theView.refreshTree();
try {
GMGenSystem.inst.openFileItem.setEnabled(true);
} catch (Exception e) {
// TODO Handle this?
}
} else {
notesToolsItem.setEnabled(true);
theView.refreshTree();
}
}
Aggregations