jtable鼠标事件弹出2次

时间:2016-08-26 08:59:14

标签: java jtable

我创建了一个在表单击时执行的事件,它打开了一个Joptionpane。 但问题是joptionpane弹出了2次。 请记住,我在生成表格后添加事件 像这样的click(table0),这些表是在从DB和一些计算中恢复之后生成的。

她是活动的代码

<Page x:Class="Hawk_PC.systemPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:Hawk_PC"
      mc:Ignorable="d" 
      Background="#03a3d2"
      d:DesignHeight="350" d:DesignWidth="525"
      Title="systemPage">


    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <Label x:Name="osInfoLabel" Content="osInfoFriendlyName" HorizontalAlignment="Left" Margin="-206,-76,0,0" VerticalAlignment="Top"/>
        <Image x:Name="image" HorizontalAlignment="Left" Height="83" Margin="-258,94,0,-119" VerticalAlignment="Top" Width="100" Source="Images/Logo.png"/>
        <Label x:Name="osInfo" Content="OS:" HorizontalAlignment="Left" Margin="-234,-76,0,0" VerticalAlignment="Top"/>
        <Label x:Name="ramInfo" Content="RAM:" HorizontalAlignment="Left" Margin="-234,-50,0,0" VerticalAlignment="Top"/>
        <Label x:Name="hddInfo" Content="HDD Storage:" HorizontalAlignment="Left" Margin="-234,2,0,0" VerticalAlignment="Top"/>
        <Label x:Name="systemHealth" Content="System Diagnose:" HorizontalAlignment="Left" Margin="-234,28,0,0" VerticalAlignment="Top"/>
        <Label x:Name="cpuInfo" Content="CPU:" HorizontalAlignment="Left" Margin="-234,-24,0,0" VerticalAlignment="Top"/>
        <Label x:Name="CPUUsage" Content="Label" HorizontalAlignment="Left" Margin="-190,-24,0,0" VerticalAlignment="Top"/>
        <Button x:Name="startScanButton" Click="startScanButton_Click" Background="Transparent" BorderThickness="0" Content="Start Diagnose" HorizontalAlignment="Left" Margin="-258,55,0,-10" VerticalAlignment="Top" Width="137" Height="31"/>


    </Grid>
</Page>

1 个答案:

答案 0 :(得分:1)

确保在每个表上只调用一次protected void click(JTable table)方法,因为每次调用它时都会添加一个新的侦听器。

另一个问题可能是您使用的mousePressed已经在鼠标按下时作出反应,您应该考虑使用mouseClicked代替仅对完整点击作出反应。