Mouse cursor events in jtable

Source: Internet
Author: User

Mouse cursor events in jtable


The mouse callback event is useful sometimes, such as sending a handling dialog box, but in Java, Sun didn't handle this special event for us, so we had to handle it when we met. Next, I will explore the path of this process, and hope you can continue.
Once you see such a problem, it will not cause a headache.
If you are using a volume upload event, such as a volume upload event or a file box, you just need to add a mouselister event to it, then, you can determine whether the operation is successful by checking the number of its unique records:
Public void mouseclick (E)
{
Int clicktimes = E. getclickcount ();
If (clicktimes = 2)
{
System. Out. println ("doublc clicked !");
}
}
If it is a table, it will be different, because the table is in the simple sequence, and then the statement is executed, no matter how you renew your account, it will not be counted as "done" or "done", and it will not be counted as "simple". It only means that you are still using "done. You can add an audible event to the table and change the preceding token to the following:
Public void mouseclick (E)
{
Int clicktimes = E. getclickcount ();
// When you perform a ticket, the first line will show
// However, this prompt does not appear after you enter the dynamic sequence in the table.
// State that the event does not recognize this time
System. Out. println ("single clicked !");
If (clicktimes = 2)
{
System. Out. println ("doublc clicked !");
}
}
Of course there will be no unexpected events.
Note: If the Enable of the table is set to false, the following statement can be used to display the Enable of the table, but is it intended !! I don't know.
What should we do now?
You may have thought of it, that is, using the two time intervals to determine whether it is necessary. However, you have to be careful. Maybe you cannot use the time interval to determine whether the transaction event can be confirmed.
At this time, you may change your proxy to the following:
...
Long firstclick = 0;
Long secondclick = 0;
Boolean click = false;
...
Public void mouseclicked (mouseevent E)
{
Int clickcount = E. getclickcount ();
If (Click = false)
{
Firstclick = new date (). gettime ();
System. Out. println ("firstclick:" + firstclick );
Click = true;
}
Else if (Click = true)
{
Secondclick = new date (). gettime ();
System. Out. println ("secondclick:" + secondclick );
Click = false;
}
// You can change this time by yourself. However, this model is also suitable. Let's take a look.
If (math. Abs (secondclick-firstclick) <200 & (secondclick-firstclick)> 30)
{
System. Out. println ("(secondclick-firstclick):" + (secondclick-firstclick ));
System. Out. println ("firstclick2:" + firstclick );
System. Out. println ("secondclick2:" + secondclick );
System. Out. println ("Double clicked! ");
}
}
Then you can add a quick one here, but it is still impossible to see the result you asked. Why? It's not just a failover. Isn't it a two-time interval? Why can't it happen !!!!
Did you forget what the author said above, that is, after the hacker enters the system, it won't be "done. In this case, there is no way for the start user to do it. Forget it. Don't want to. Go out and take a walk.
When we get back, we may just need to clear our head and convert the mousepressed method to this.
Public void mousepressed (mouseevent E)
{
System. Out. println ("pressed !");
}
Let me run the program. In the simple tables, the following figure shows the pressed! In this line, this line is normal, because this is both a simple line and a click, I just wrote, there is a good image below, there are two pressed! . This makes me wake up. It turns out that I have been using it for two times.
Haha, I laughed.
Do you know how to do this? I still don't know !!!!!
The content in the following mouseclicked is fully written into the pressed event. Do not change the content in one sentence:
Public void mousepressed (mouseevent E)
{
Int clickcount = E. getclickcount ();
If (Click = false)
{
Firstclick = new date (). gettime ();
System. Out. println ("firstclick:" + firstclick );
Click = true;
}
Else if (Click = true)
{
Secondclick = new date (). gettime ();
System. Out. println ("secondclick:" + secondclick );
Click = false;
}
If (math. Abs (secondclick-firstclick) <200 & (secondclick-firstclick)> 30)
{
System. Out. println ("(secondclick-firstclick):" + (secondclick-firstclick ));
System. Out. println ("firstclick2:" + firstclick );
System. Out. println ("secondclick2:" + secondclick );
System. Out. println ("Double clicked! ");
}
}
Have you seen the expected result !!!
Okay.
I put all the programs below (I used it for zookeeper, but it is a bit tricky, but it will certainly work ).
Import java. AWT. borderlayout;

Import java. AWT. dimension;
Import java. AWT. event. mouseevent;
Import java. AWT. event. mouselistener;

Import javax. Swing. jbutton;
Import javax. Swing. jframe;
Import javax. Swing. jtable;
Import java. util. date;
Public class test
Extends jframe
{
Private borderlayout borderlayout1 = new borderlayout ();
Jframe frame = new jframe ();
Private jbutton jbutton1 = new jbutton ();
String [] Title =
{"Table head 1", "Table head 2 "};
String [] [] content =
{
{"1", "2 "},
{"3", "4 "}};
Jtable table;
Long firstclick = 0;
Long secondclick = 0;
Boolean click = false;
Public test ()
{
Try
{
Table = new jtable (content, title );
Jbinit ();
This. setdefaclocloseoperation (jframe. exit_on_close );

}
Catch (exception E)
{
E. printstacktrace ();
}
}

Public static void main (string [] ARGs)
{

New Test (). setvisible (true );
}

Private void jbinit ()
Throws exception
{
This. getcontentpane (). setlayout (borderlayout1 );
This. setsize (new dimension (441,305 ));
Jbutton1.settext ("jbutton1 ");

Jbutton1.addmouselistener (New mouselistener ()
{
/**
* Core generation
*/
Public void mouseclicked (mouseevent E)
{
Int clickcount = E. getclickcount ();
If (clickcount = 2)
{
System. Out. println ("Double clicked! ");
}
}
Public void mousepressed (mouseevent E)
{
}
Public void mousereleased (mouseevent E)
{
}
Public void mouseentered (mouseevent E)
{
}
Public void mouseexited (mouseevent E)
{
}
});
Table. addmouselistener (New mouselistener ()
{
/**
* Core generation
*/
Public void mouseclicked (mouseevent E)
{
Int clickcount = E. getclickcount ();
If (Click = false)
{
Firstclick = new date (). gettime ();
System. Out. println ("firstclick:" + firstclick );
Click = true;
}
Else if (Click = true)
{
Secondclick = new date (). gettime ();
System. Out. println ("secondclick:" + secondclick );
Click = false;
}
If (math. Abs (secondclick-firstclick) <200 & (secondclick-firstclick)> 30)
{
System. Out. println ("(secondclick-firstclick):" + (secondclick-firstclick ));
System. Out. println ("firstclick2:" + firstclick );
System. Out. println ("secondclick2:" + secondclick );
System. Out. println ("Double clicked! ");
}
}
Public void mousepressed (mouseevent E)
{
If (Click = false)
{
Firstclick = new date (). gettime ();
System. Out. println ("firstclick:" + firstclick );
Click = true;
}
Else if (Click = true)
{
Secondclick = new date (). gettime ();
System. Out. println ("secondclick:" + secondclick );
Click = false;
}
If (math. Abs (secondclick-firstclick) <200 & (secondclick-firstclick)> 30)
{
System. Out. println ("(secondclick-firstclick):" + (secondclick-firstclick ));
System. Out. println ("firstclick2:" + firstclick );
System. Out. println ("secondclick2:" + secondclick );
System. Out. println ("Double clicked! ");
}
}

Public void mousereleased (mouseevent E)
{
}

Public void mouseentered (mouseevent E)
{
}

Public void mouseexited (mouseevent E)
{
}
});
This. getcontentpane (). Add (jbutton1, borderlayout. North );
This. getcontentpane (). Add (table, borderlayout. South );

}

}
Remember, don't forget. Things will be shared with everyone !!~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.