JEditor ta = new JEditor(defaults); ta.setGutterHandler(new TestGutterHandler());and:
public class MyGutterHandler implements GutterHandler { private Image image = null; public MyGutterHandler() { URL url = thi.getClass().getResource("breakpoint.png"); try { image = ImageIO.read(url); } catch (IOException ex) { } } @Override public boolean isPainting(int line) { // only the line of number 103 will have the image return line == 103; } @Override public boolean handleClick(Gutter gutter, int mouseButton, int x, int y) { JPopupMenu menu = new JPopupMenu(); int number = gutter.getLineNumber(y); menu.add(new JMenuItem("An Action on " + number)); menu.add(new JMenuItem("Another Action")); menu.show(gutter, x, y); return true; } @Override public void paint(Graphics gfx, int line, int x, int y) { gfx.drawImage(image, x - 16, y - 10, null); } }We will have the following result:
JEditor ta = new JEditor(defaults); MyGutterHandler handler = new MyGutterHandler(); URL debugURL = ... handler.addImageResource("debug", debugURL); handler.addImage(103, "debug"); ta.setGutterHandler(handler);and:
private class MyGutterHandler extends AbstractGutterHandler { public boolean handleClick(Gutter gutter, int mouseButton, int x, int y) { if (mouseButton == MouseEvent.BUTTON3) { JPopupMenu menu = new JPopupMenu(); int number = gutter.getLineNumber(y); menu.add(new JMenuItem("An Action on " + number)); menu.show(gutter, x, y); return true; } else { return false; } } public void handleMoved(Gutter gutter, int x, int y) { int number = gutter.getLineNumber(y); if (isPainting(number)) { this.showTooltip("The tooltip on line" + number); } else { this.hideTooltip(); } } }
Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence