Mouse Events Not Registering


There

I'm trying to draw lines on a drawing panel using the mouse to press, drag and release to draw a line. I also need to add functionality to allow the user to change the color of the line. I've just started on this and somehow I cannot get the mouse events to register.

I've enclosed the code below. Could someone please tell me what I'm missing.

Please help me figure out my problem. Why are the mouse clicks not being registered.

Posted On: Tuesday 23rd of October 2012 11:35:23 PM Total Views:  225
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




How to make Resize JButton() on mouse click...

Hi ... I am herewith enclosed my sample code for resize the JButton(),But This one resize the when will be extend the Button Caption letters,But i want mouse click resize the without button caption or with caption. sample code : package Resize; import java.awt.Container; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import java.awt.Dimension; import java.awt.ComponentOrientation; public class ReButton{ public static boolean RIGHT_TO_LEFT = false; public static void addComponents(Container contentPane) { if (RIGHT_TO_LEFT) { contentPane.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT); } contentPane.setLayout(new FlowLayout()); contentPane.add(new JButton("1")); contentPane.add(new JButton("100")); contentPane.add(new JButton("100 100")); contentPane.add(new JButton("100 100 100")); contentPane.add(new JButton("100 100 100 100")); contentPane.add(new JButton("5")); } private static void createAndShowGUI() { JFrame frame = new JFrame("FlowLayoutDemo") { public Dimension getMinimumSize() { Dimension prefSize = getPreferredSize(); return new Dimension(100, prefSize.height); } }; frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. addComponents(frame.getContentPane()); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } } ************************
VIEWS ON THIS POST

97

Posted on:

Thursday 18th October 2012
View Replies!

problem in drawing deleting a line on the click of a mouse

, i tried to create a code which draws lines across an image when line segment button is clicked.then on the click of a button at a point a line is already thr,the line should get replaced by a white line(that is line should be deleted),if the line is not there then on clicking at that point line should be drawn nd is mouse is dragged from a particular line,then line gets shifted from previous to position whr mouse is released... an arrar harr[] is used to store positions whr line is drawn nd stores 9999 whr a white line is drawn...but the code doesnt delete line on the click.. please help me.. i am attaching the code //this program is for adding lines to image already loaded by openpic prog import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; public class openpic2 extends JFrame { // Instance variables JTextField m_fileNameTF = new JTextField(15); JFileChooser m_fileChooser = new JFileChooser();int flag2=0;int t=0; DrawingPanel imagepanel; Image img;int arr[]; int height,width,hcount,vcount,flag=3,click,clear; JavaFilter fJavaFilter; int mouseX,mouseY,mx,my; int varr[]=new int[1000]; int harr[]=new int[1000]; public static void main(String[] args) { JFrame window = new openpic2(); window.setVisible(true); } // constructor openpic2() { // set the Text field to Read Only mode m_fileNameTF.setEditable(false); // Choose only files, not directories m_fileChooser.setFileSelectionMode ( JFileChooser.FILES_ONLY); // Set filter for Java source files. fJavaFilter = new JavaFilter(); m_fileChooser.setFileFilter (fJavaFilter); //... Add Open Button and its listeners JButton openButton = new JButton("Open"); JButton lineButton = new JButton("line segment"); JButton wordButton=new JButton("word segment"); JButton clearButton=new JButton("clear"); openButton.addActionListener(new OpenAction()); lineButton.addActionListener(new LineAction()); wordButton.addActionListener(new wordAction()); clearButton.addActionListener(new clearAction()); //... Create contant pane, layout components JPanel content = new JPanel(); content.setLayout(new BorderLayout()); JPanel buttonpanel=new JPanel(); buttonpanel.add(openButton); buttonpanel.add(m_fileNameTF); buttonpanel.add(lineButton); buttonpanel.add(wordButton); buttonpanel.add(clearButton); content.add(buttonpanel,"South"); // Create JPanel canvas to hold the picture imagepanel = new DrawingPanel(); //imagepanel.addMouseListener(new MouseClickListener()); // Create JScrollPane to hold the canvas containing the picture JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroller.setPreferredSize(new Dimension(500,300)); scroller.setViewportView(imagepanel); scroller.setViewportBorder( BorderFactory.createLineBorder(Color.black)); // Add scroller pane to Panel content.add(scroller,"Center"); //Set window characteristics this.setTitle("File Browse and View"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setContentPane(content); this.pack(); } class DrawingPanel extends JPanel { int x,y; public DrawingPanel() { for(int i=0;i
VIEWS ON THIS POST

97

Posted on:

Thursday 18th October 2012
View Replies!

problem in attaching mouselistener on a imagepanel

, i am trying to add a mouselistener in a panel which is a part of a frame.....but the listener is not responding to click of mouse........please help me in finding where i m wrong..... i am attching the whole code import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; public class openpic2 extends JFrame { // Instance variables JTextField m_fileNameTF = new JTextField(15); JFileChooser m_fileChooser = new JFileChooser(); DrawingPanel imagepanel; Image img;int arr[]; int height,width,hcount,vcount,flag,click; JavaFilter fJavaFilter; int mouseX,mouseY; public static void main(String[] args) { JFrame window = new openpic2(); window.setVisible(true); } // constructor openpic2() { // set the Text field to Read Only mode m_fileNameTF.setEditable(false); // Choose only files, not directories m_fileChooser.setFileSelectionMode ( JFileChooser.FILES_ONLY); // Set filter for Java source files. fJavaFilter = new JavaFilter(); m_fileChooser.setFileFilter (fJavaFilter); //... Add Open Button and its listeners JButton openButton = new JButton("Open"); JButton lineButton = new JButton("line segment"); JButton wordButton=new JButton("word segment"); openButton.addActionListener(new OpenAction()); lineButton.addActionListener(new LineAction()); wordButton.addActionListener(new wordAction()); //... Create contant pane, layout components JPanel content = new JPanel(); content.setLayout(new BorderLayout()); JPanel buttonpanel=new JPanel(); buttonpanel.add(openButton); buttonpanel.add(m_fileNameTF); buttonpanel.add(lineButton); buttonpanel.add(wordButton); content.add(buttonpanel,"South"); // Create JPanel canvas to hold the picture imagepanel = new DrawingPanel(); //imagepanel.addMouseListener(new MouseClickListener()); // Create JScrollPane to hold the canvas containing the picture JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroller.setPreferredSize(new Dimension(500,300)); scroller.setViewportView(imagepanel); scroller.setViewportBorder( BorderFactory.createLineBorder(Color.black)); // Add scroller pane to Panel content.add(scroller,"Center"); //Set window characteristics this.setTitle("File Browse and View"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setContentPane(content); this.pack(); } class DrawingPanel extends JPanel { int harr[]=new int[100]; int varr[]=new int[100]; int x,y; public DrawingPanel() { for(int i=0;i
VIEWS ON THIS POST

99

Posted on:

Thursday 18th October 2012
View Replies!

disabling mouse effects on swing forms

I want to disable mouse on swing forms. Probably you will recommend "If you dont want to process mouse events then dont add any of MouseListeners." I am not asking that.My problem is about focusing.Only with keyboard i want to manage the focusing... Mouse must be useless focusing in UIs.Because wherever i click with mouse swing components ,cursor is jumping to clicked component in any case. I dont want that.I want mouse is useless for focusing. How can i do that
VIEWS ON THIS POST

80

Posted on:

Thursday 18th October 2012
View Replies!

opening a window on mouse over

i have developed a tree through swing.Now i want to open a window in the same frame which details that node.(it doesnot matter if its a pop-up or a new Jframe.(please explain in details kindly.) here is the code :- package edu.berkeley.guir.prefuse.demos; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Image; import java.awt.Paint; import java.awt.Toolkit; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.geom.Point2D; import java.io.InputStream; import java.io.StringBufferInputStream; import java.net.URL; import java.util.Iterator; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; //import org.apache.bcel.generic.NEW; import myExtension.MyFocusListener; import myExtension.MyNodeShape; import myExtension.MyTreeApplet; import edu.berkeley.guir.prefuse.AggregateItem; import edu.berkeley.guir.prefuse.Display; import edu.berkeley.guir.prefuse.EdgeItem; import edu.berkeley.guir.prefuse.FocusManager; import edu.berkeley.guir.prefuse.ItemRegistry; import edu.berkeley.guir.prefuse.NodeItem; import edu.berkeley.guir.prefuse.VisualItem; import edu.berkeley.guir.prefuse.action.ActionSwitch; import edu.berkeley.guir.prefuse.action.RepaintAction; import edu.berkeley.guir.prefuse.action.animate.ColorAnimator; import edu.berkeley.guir.prefuse.action.animate.FontAnimator; import edu.berkeley.guir.prefuse.action.animate.LocationAnimator; import edu.berkeley.guir.prefuse.action.animate.PolarLocationAnimator; import edu.berkeley.guir.prefuse.action.animate.SizeAnimator; import edu.berkeley.guir.prefuse.action.assignment.ColorFunction; import edu.berkeley.guir.prefuse.action.filter.TreeEdgeFilter; import edu.berkeley.guir.prefuse.action.filter.TreeFilter; import edu.berkeley.guir.prefuse.action.filter.WindowedTreeFilter; import edu.berkeley.guir.prefuse.activity.ActionList; import edu.berkeley.guir.prefuse.activity.SlowInSlowOutPacer; import edu.berkeley.guir.prefuse.activity.ThereAndBackPacer; import edu.berkeley.guir.prefuse.event.FocusEvent; import edu.berkeley.guir.prefuse.event.FocusListener; import edu.berkeley.guir.prefuse.focus.DefaultFocusSet; import edu.berkeley.guir.prefuse.graph.DefaultTreeNode; import edu.berkeley.guir.prefuse.graph.Graph; import edu.berkeley.guir.prefuse.graph.Tree; import edu.berkeley.guir.prefuse.graph.TreeNode; import edu.berkeley.guir.prefuse.graph.external.DatabaseLoader; import edu.berkeley.guir.prefuse.graph.io.TabDelimitedTreeReader; import edu.berkeley.guir.prefuse.graph.io.XMLGraphReader; import edu.berkeley.guir.prefuse.render.DefaultEdgeRenderer; import edu.berkeley.guir.prefuse.render.DefaultNodeRenderer; import edu.berkeley.guir.prefuse.render.DefaultRendererFactory; import edu.berkeley.guir.prefuse.render.ImageFactory; import edu.berkeley.guir.prefuse.render.PolygonRenderer; import edu.berkeley.guir.prefuse.render.Renderer; import edu.berkeley.guir.prefuse.render.ShapeRenderer; import edu.berkeley.guir.prefuse.render.TextImageItemRenderer; import edu.berkeley.guir.prefuse.render.TextItemRenderer; import edu.berkeley.guir.prefuse.util.ColorMap; import edu.berkeley.guir.prefuse.util.StringAbbreviator; import edu.berkeley.guir.prefusex.controls.DragControl; import edu.berkeley.guir.prefusex.controls.FocusControl; import edu.berkeley.guir.prefusex.controls.NeighborHighlightControl; import edu.berkeley.guir.prefusex.controls.PanControl; import edu.berkeley.guir.prefusex.controls.RotationControl; import edu.berkeley.guir.prefusex.controls.SubtreeDragControl; import edu.berkeley.guir.prefusex.controls.ToolTipControl; import edu.berkeley.guir.prefusex.controls.ZoomControl; import edu.berkeley.guir.prefusex.controls.ZoomingPanControl; import edu.berkeley.guir.prefusex.layout.IndentedTreeLayout; import edu.berkeley.guir.prefusex.layout.RadialTreeLayout; import edu.berkeley.guir.prefusex.layout.TopDownTreeLayout; import edu.berkeley.guir.prefusex.layout.VerticalTreeLayout; /** * Demo application showcasing the use of an animated radial tree layout to * visualize a graph. This is a re-implementation of Ping Yee et al.'s * Animated Exploration of Dynamic Graphs with Radial Layout. * * @version 1.0 * @author Jeffrey Heer prefuse(AT)jheer.org */ public class MyTreeTest extends JFrame implements HyperlinkListener , FocusListener{ public static final String GRAPH_GUIR = "C:/eclipse/workspace/PREFUSE/Demos/etc/myData.xml"; public static final String GRAPH_FRIENDSTER = "C:/eclipse/workspace/PREFUSE/Demos/etc/friendster.xml"; public static final String GRAPH_TERROR = "C:/eclipse/workspace/PREFUSE/Demos/etc/terror.xml"; public static final String nameField = "label"; public static void main(String[] argv) { new RadialGraphDemo(); } // public MyTreeTest() { super("RadialLayout Demo"); try { String str ="LABEL\tPARENTLABEL\tSCORE" + "\nTSA\tParent"+ "\nHealth and Insurance\tOrganization And Maintenance\t-999.0"+ "\nITMS\tOrganization And Maintenance\t-999.0"+ "\nProjects\tTSA\t-999.0"+ "\nFixed Infrastructure\tOrganization And Maintenance\t87.94"+ "\nLife Insurance\tOrganization And Maintenance\t-999.0"+ "\nSecurity Investigation\tSecurity\t-999.0"+ "\nSecurity\tTSA\t-999.0"+ "\nOrganization And Maintenance\tTSA\t87.94"+ "\nOM-AVL-11\tFixed Infrastructure\t89.04"+ "\nOM-AVL-13\tFixed Infrastructure\t-999.0"; InputStream is = new StringBufferInputStream(str); TabDelimitedTreeReader treeReader = new TabDelimitedTreeReader(); String inputFile = GRAPH_GUIR; XMLGraphReader gr = new XMLGraphReader(); gr.setNodeType(DefaultTreeNode.class); //Graph graph = gr.loadGraph(inputFile); Tree graph = treeReader.loadTree(is); //AggregateItem aggItem = new AggregateItem(); Iterator nodeIterator = graph.getNodes(); while(nodeIterator.hasNext()){ TreeNode node = (DefaultTreeNode)nodeIterator.next(); //System.out.println("NODE ATTIBUTES : "+node.getAttributes()); node.setAttribute("image","C:/eclipse/workspace/PREFUSE/src/myExtension/RedEventBig.jpg"); if(node.getAttribute("LABE").equalsIgnoreCase("Security")){ // aggItem.setAsChild(node); } } // create display and filter ItemRegistry registry = new ItemRegistry(graph); System.out.println("REGISTRY OBJECT IS "+registry); Display display = new Display(); Iterator iterator = registry.getItems(); while(iterator.hasNext()){ VisualItem item = (VisualItem)iterator.next(); //nodeRenderer.getShape(item); } // initialize renderers TextItemRenderer nodeRenderer = new TextItemRenderer(); nodeRenderer.setTextAttributeName("LABE"); nodeRenderer.setMaxTextWidth(175); //System.out.println("SHAPE IS "+nodeRenderer.getShape()); //nodeRenderer.setAbbrevType(StringAbbreviator.NAME); //nodeRenderer.setRoundedCorner(2,2); Renderer edgeRenderer = new DefaultEdgeRenderer(); registry.setRendererFactory(new DefaultRendererFactory(nodeRenderer, edgeRenderer)); // initialize action pipelines ActionList layout = new ActionList(registry); //layout.add(new TreeFilter(true)); layout.add(new TreeFilter(true)); layout.add(new VerticalTreeLayout()); layout.add(new DemoColorFunction(3)); ActionList update = new ActionList(registry); update.add(new DemoColorFunction(3)); update.add(new RepaintAction()); //update.add(new ActionSwitch()); ActionList animate = new ActionList(registry, 1000, 10); animate.setPacingFunction(new SlowInSlowOutPacer()); //animate.add(new PolarLocationAnimator()); //animate.add(new ColorAnimator()); animate.add(new RepaintAction()); animate.add(new LocationAnimator()); animate.add(new FontAnimator()); animate.alwaysRunAfter(layout); // initialize display display.setItemRegistry(registry); display.setSize(1100,700); display.setBackground(Color.WHITE); //display.addControlListener(new MyTreeApplet()); //display.addFocusListener(new MyFocusListener()); display.addControlListener(new FocusControl(layout)); display.addControlListener(new FocusControl(1,FocusManager.DEFAULT_KEY)); display.addControlListener(new DragControl()); display.addControlListener(new PanControl()); display.addControlListener(new ZoomControl()); //display.addControlListener(new ToolTipControl()); //display.addControlListener(new NeighborHighlightControl(update)); display.setUseCustomTooltips(true); display.addControlListener(new ToolTipControl("ObjectName")); //display.addControlListener(new ZoomingPanControl()); //display.addControlListener(new SubtreeDragControl()); //display.addControlListener(new RotationControl()); Display overview = new Display(registry); overview.setBorder(BorderFactory.createLineBorder(Color.RED, 1)); overview.setSize(250,250); overview.zoom(new Point2D.Float(0,0),0.1); //display.add(overview); registry.getFocusManager().putFocusSet( FocusManager.HOVER_KEY, new DefaultFocusSet()); // create and display application window setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().add(display, BorderLayout.CENTER); pack(); setVisible(true); // run filter+layout, and perform initial animation layout.runNow(); } catch ( Exception e ) { e.printStackTrace(); } } // /*public class MouseOverEvents extends MouseAdapter { public void mouseEntered(MouseEvent e) { (TreeNode)e.get("TreeNode"); repaint(); } }*/ public class DemoColorFunction extends ColorFunction { private Color graphEdgeColor = Color.LIGHT_GRAY; private Color highlightColor = new Color(50,50,255); private Color focusColor = new Color(255,50,50); private Color lightGray = new Color(220,220,255); private ColorMap colorMap; public DemoColorFunction(int thresh) { colorMap = new ColorMap( ColorMap.getInterpolatedMap(thresh+1, Color.RED, Color.BLACK), 0, thresh); } // public Paint getFillColor(VisualItem item) { if ( item instanceof NodeItem ) { Color pastelRed = new Color(255,125,125); return lightGray; } else if ( item instanceof AggregateItem ) { return Color.LIGHT_GRAY; } else if ( item instanceof EdgeItem ) { return getColor(item); } else { return Color.BLACK; } } // public Paint getColor(VisualItem item) { if ( item.isFocus() ) { return focusColor; } else if ( item.isHighlighted() ) { return highlightColor; } else if (item instanceof NodeItem) { int d = ((NodeItem)item).getDepth(); return colorMap.getColor(d); } else if (item instanceof EdgeItem) { EdgeItem e = (EdgeItem) item; if ( e.isTreeEdge() ) { int d, d1, d2; d1 = ((NodeItem)e.getFirstNode()).getDepth(); d2 = ((NodeItem)e.getSecondNode()).getDepth(); d = Math.max(d1, d2); return colorMap.getColor(d); } else { return graphEdgeColor; } } else { return Color.BLACK; } } // } // end of inner class DemoColorFunction /* (non-Javadoc) * @see javax.swing.event.HyperlinkListener#hyperlinkUpdate(javax.swing.event.HyperlinkEvent) */ public void hyperlinkUpdate(HyperlinkEvent event) { System.out.println("THIS IS IN HYPERLINK UPDATE "); } /* (non-Javadoc) * @see edu.berkeley.guir.prefuse.event.FocusListener#focusChanged(edu.berkeley.guir.prefuse.event.FocusEvent) */ public void focusChanged(FocusEvent e) { System.out.println("INSIDE FOCUS LISTENER"); } } // end of classs RadialGraphDemo
VIEWS ON THIS POST

86

Posted on:

Thursday 18th October 2012
View Replies!

mouse listening

i know of a way to navigate across a GUI using a mouse and get the x, y coordinates as i go but how would i be able to listen for and read the RGB values of the pixel i am hovering over
VIEWS ON THIS POST

73

Posted on:

Thursday 18th October 2012
View Replies!

mouseClicked event for the "Cancel button"

I am trying to write the mouseClicked event for the "Cancel button" where the entire window has to close on pressing the Cancel button. I wrote the following code: package my.initPckg; import com.jcraft.jsch.*; import java.awt.*; import javax.swing.*; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import java.awt.Font; import javax.swing.JOptionPane; import javax.swing.SwingConstants; import javax.swing.JTextField; import javax.swing.JPasswordField; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class PmtGui extends JFrame { private JPanel contentPane; private JTextField textFieldHN; private JTextField textFieldPW; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { PmtGui frame = new PmtGui(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public PmtGui() { setTitle("Performance Monitor Tool for 8950 SAM"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblHostName = new JLabel("Host Name:"); lblHostName.setFont(new Font("Tahoma", Font.BOLD, 12)); lblHostName.setBounds(117, 83, 83, 14); contentPane.add(lblHostName); JLabel lblPassword = new JLabel("Password:"); lblPassword.setFont(new Font("Tahoma", Font.BOLD, 12)); lblPassword.setBounds(117, 127, 67, 14); contentPane.add(lblPassword); textFieldHN = new JTextField(); textFieldHN.setBounds(210, 81, 122, 20); contentPane.add(textFieldHN); textFieldHN.setColumns(10); JButton btnConnect = new JButton("Connect"); btnConnect.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { String host = textFieldHN.getText(); String passwd = textFieldPW.getText(); String user = host.substring(0, host.indexOf('@')); host = host.substring(host.indexOf('@')+1); try { JSch jsch=new JSch(); Session session=jsch.getSession(user, host, 22); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.setHost(host); session.setPassword(passwd); session.connect(); Channel channel = session.openChannel("shell"); channel.setInputStream(System.in); channel.setOutputStream(System.out); channel.connect(); } catch (Exception e){ System.out.println(e); } } }); btnConnect.setBounds(117, 193, 89, 23); contentPane.add(btnConnect); JButton btnCancel = new JButton("Cancel"); btnCancel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { contentPane.setVisible(false); } }); btnCancel.setBounds(234, 193, 89, 23); contentPane.add(btnCancel); JLabel lblConnectToServer = new JLabel("Connect to Server"); lblConnectToServer.setFont(new Font("Tahoma", Font.BOLD, 13)); lblConnectToServer.setBounds(148, 29, 146, 14); contentPane.add(lblConnectToServer); textFieldPW = new JPasswordField(20); textFieldPW.setBounds(210, 125, 122, 20); contentPane.add(textFieldPW); textFieldPW.setColumns(10); } }
VIEWS ON THIS POST

73

Posted on:

Sunday 21st October 2012
View Replies!

click the mouse in a coordinate

Is it possible to click the mouse in a coordinate, so it give the x,y horizontal with regard to the (0,0) point
VIEWS ON THIS POST

81

Posted on:

Monday 22nd October 2012
View Replies!

Change the color of a JTable cell on mouse click

Can anyone suggest a solution for this problem I have a JTable in which I want to set different fore colors for different cells on mouse click.(Please note that not for rows or columns but for individual cells). ie initially if the fore color is black, If I click on the cell it should turned to yellow. Again if I click it should be Green and so on. Also I want to set two or 3 different colors for the text in a particular cell (The text is separated with space and each of these text should be of different color!!) When changing the fore colors I don't want to change the backcolor.It is by default the white color itself. Thank you
VIEWS ON THIS POST

89

Posted on:

Monday 22nd October 2012
View Replies!

JPopupMenu disappear after mouse exits...

I'm trying to get the JPopupMenu to disappear after the mouseExits and after a wait of 3 seconds if the mouse does not come back in. However it's not working as I planned. The JPopupMenu has a few JMenuItem's on them which are all set to setOpaque(false). And therein lies the issue. If I set the menuitems to setOpaque(true) than my code works fine... however its only when they are setOpaque(false) that the JPopupMenu will disappear after 3 regardless of if the mouse is over them or not... I over rode JPopupMenu and added a MouseListener to get if the mouse enters or exits... here is the code for the mouseListener methods which is the only thing I over rode ( besides paintComponent but that does not apply here).. subclassed JPopupMenu MouseListener Methods ... also implements Runnable to get a timer going.. public void mouseClicked(MouseEvent arg0) {}; public void mouseEntered(MouseEvent arg0) { if(timer != null && timer.isAlive()) timer.interrupt(); } public void mouseExited(MouseEvent arg0) { timer = new Thread(this); timer.start(); } public void mousePressed(MouseEvent arg0) {}; public void mouseReleased(MouseEvent arg0) {}; public void run() { try{ Thread.sleep(3000); }catch(InterruptedException e){ return; } this.setVisible(false); }
VIEWS ON THIS POST

94

Posted on:

Monday 22nd October 2012
View Replies!

How to avoid mouse click event getting called when user press,drag and release the mouse

I have a Jtable component in my UI. I have implemented sorting of columns on click of column header using a Comparator.. The comparator is called in the mouseClicked event. My problem is.. when we try to resize the column i.e click on the border of columns drag and release... the mouse click event gets fired and that particular column gets sorted... I dont want this to happen.. This event of dragging and expand the column size must not trigger the mouseClick.. Is there any work around to avoid this\t I also tried giving empty implementation for mousePressed and mouseReleased events.... Please help..
VIEWS ON THIS POST

87

Posted on:

Monday 22nd October 2012
View Replies!

Regarding JTable mouse events

I have a JTable with some row data with one cell contains hyperlink on it, when we click on that link,it will take arguments of row data cell,and click it, it should open another dialog box, the table data should be displayed on this dialog box.please healp me as early as possible. Thank You in advance raja.tadi@tcs.com
VIEWS ON THIS POST

75

Posted on:

Monday 22nd October 2012
View Replies!

mouse event for an array of object

Is it possible add moseDragged event for an array of rectangle...
VIEWS ON THIS POST

110

Posted on:

Monday 22nd October 2012
View Replies!

weird mouse icon change

my table has a sorter and my gui has a L&F switch; when i sort columns, change L&F and then hover any table header, mouse changes to this. i'm using java6 and winXp How can i avoid this TiA
VIEWS ON THIS POST

79

Posted on:

Monday 22nd October 2012
View Replies!

problem with mouseMoved method

Hi. My mouseMoved method dosnt seem to be registering at all, and I cant figure out why not! Heres what Ive got: public class BrowserMouse implements MouseListener,MouseMotionListener{ public BrowserMouse(){ } public void mouseClicked (MouseEvent e) { System.out.println("mouse clicked"); } public void mouseReleased (MouseEvent e) { System.out.println("releasing on Browser"); } public void mouseExited (MouseEvent e) { System.out.println("Exiting Browser"); } public void mouseEntered (MouseEvent e) { System.out.println("Entering Browser"); } public void mouseMoved(MouseEvent e) { System.out.println("moving ON BROWSER"); } public void mousePressed(MouseEvent e) { System.out.println("pressing ON BROWSER"); } public void mouseDragged (MouseEvent e){ System.out.println("draging ON BROWSER"); } }
VIEWS ON THIS POST

72

Posted on:

Monday 22nd October 2012
View Replies!

Swing - detect mouse click outside modal JDialog boundary

I have a JFrame with objects located on it at specific positions. I'd like to pop up a modal JDialog on top of that JFrame and let the user click on the object pixels on the underlying JFrame and detect those mouse clicks from within the JDialog so that I can show some meta information from within the JDialog. I know that the user cannot click on the actual JFrame objects once the JDialog is showing, but if they move the JDialog to the side, they can physically click the mouse on the pixel locations of the JFrame objects, and it's those clicks I'd like to detect from within the JDialog. When I look at the standard MouseEvent's they all seem to be constrained to the JDialog boundaries (which is fair enough for normal use), and I know that what I'd like to do here is non-standard, just wondering if anyone has any ideas on how I might approach it. Cheers James
VIEWS ON THIS POST

116

Posted on:

Monday 22nd October 2012
View Replies!

mouseEntered and exited events to paint

im trying to create a program what when the mouse enters the left side of my window the background should change to red; if the mouse moves into the right side i need to change it to green. once i find the size of my window by saying d = yourFrame.getSize(); where do i calculate to find which side my mouse pointer is on at that time. could i use an if else statement in the mouseEntered and mouseExited and how could i create variables that define the left half of my window and right half
VIEWS ON THIS POST

60

Posted on:

Tuesday 23rd October 2012
View Replies!

jtable right mouse click

hi! how can i set a selection with right mouse click in jtable it only works with left mouse clicks. my table has single_selection mode. thx martin
VIEWS ON THIS POST

131

Posted on:

Tuesday 23rd October 2012
View Replies!

Submenu in a submenu does not open when the mouse moves over it

I have a web browser application with a favorites menu. The menu has an two options to import favorites from IE and Firefox. When the application imports favorites from IE, it places the favorites as items under the import option. If there are folders of favorites, it will add a submenu containing the favorites in the folder. The problem I have is that after I import the favortites and it creates the submenus, some submenu's don't open the mouse pointer is moved over them. Some menu work fine and when the mouse pointer is moved over such a, then the other submenu open fine as well, but only after selecting a submenu that listens. I have debugged the code and the menu items are added before selecting the menu. I don't need a listener for a submenu Does anyone have an idea what I am overlooking Thanx
VIEWS ON THIS POST

72

Posted on:

Tuesday 23rd October 2012
View Replies!

JSlider and "mouse click"

JSlider component behaves the same way (i.e. adjusting works OK) no matter if I click with left or right mouse click. But, I need to distinguish between left and right mouse click. How can I do that
VIEWS ON THIS POST

70

Posted on:

Tuesday 23rd October 2012
View Replies!