java - Drag & Drop - Slide from a jTextPane white part? -
if drag & drop selected text jtextpane window work.
but there way drag & drop text jtextpane clicking-sliding directly white part of jtextpane area ? (mean whithout need click on selected-highlighted text)
or auto-move mouse pointer highlighted text ? (but appear "less clean" solution : is solution ?)
what call "white part", area in jtextpane, there no highlighted text
simple example :
/** * basic frame settings */ setbounds(100, 100, 450, 300); contentpane = new jpanel(); contentpane.setborder(new emptyborder(5, 5, 5, 5)); setcontentpane(contentpane); contentpane.setlayout(null); jtextpane textpane = new jtextpane(); textpane.setbounds(143, 73, 143, 78); contentpane.add(textpane); textpane.seteditable(false); textpane.settext("hello"); textpane.setdragenabled(true); selected text can dnd
but how possible dnd white area of jtextpane ?
here more clear example show bit, how possible :
boolean b = true; setbounds(100, 100, 450, 300); contentpane = new jpanel(); contentpane.setborder(new emptyborder(5, 5, 5, 5)); setcontentpane(contentpane); contentpane.setlayout(null); final jtextpane textpane = new jtextpane(); textpane.addmouselistener(new mouseadapter() { @override public void mousepressed(mouseevent e) { robot robot = null; try { robot = new robot(); } catch (awtexception ex) { logger.getlogger(testframe.class.getname()).log( level.severe, null, ex); } // set mouse x,y position robot.mousemove(textpane.getlocationonscreen().x, textpane.getlocationonscreen().y); if (b) { // simulate mouse double click robot.mousepress(inputevent.button1_mask); robot.mousepress(inputevent.button1_mask); b = false; } } }); textpane.setbounds(143, 73, 143, 78); contentpane.add(textpane); textpane.seteditable(false); textpane.settext("hello"); textpane.setdragenabled(true); does have kind of better solution ??
Comments
Post a Comment