我将3个单选按钮(姓名查询,班级查询,年龄查询)放在一个group中,第一次按无论什么就只出现自己的那个窗口,但是再按下一个时就会出现自己及自己前面的窗口,原因是什么,我用的windowbuilder
final Button btnRadioButton = new Button(group, SWT.RADIO);
btnRadioButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if(btnRadioButton.getSelection()){
SelectNo window = new SelectNo();
window.open();}
}
});
就是这样的三个监听
swt中单选按钮问题
答案:2 悬赏:80 手机版
解决时间 2021-02-11 00:12
- 提问者网友:黑米和小志
- 2021-02-09 23:18
最佳答案
- 五星知识达人网友:长青诗
- 2021-02-09 23:24
这个与用什么工具的关系不大。
----------------------------------------------------------------------
再按下一个时就会出现自己及自己前面的窗口
----------------------------------------------------------------------
如果是点第一次,出现一个,
点第二次出现两个,
第三次,出现三个,
那么我觉得,是你的侦听器添加多了造成的。
你检查一下,是不是你在选择单选安钮时,又一次的添加了侦听器。
----------------------------------------------------------------------
再按下一个时就会出现自己及自己前面的窗口
----------------------------------------------------------------------
如果是点第一次,出现一个,
点第二次出现两个,
第三次,出现三个,
那么我觉得,是你的侦听器添加多了造成的。
你检查一下,是不是你在选择单选安钮时,又一次的添加了侦听器。
全部回答
- 1楼网友:长青诗
- 2021-02-09 23:46
已山寨,复制粘贴即可
import java.awt.borderlayout;
import java.awt.component;
import java.awt.dimension;
import java.util.date;
import javax.swing.borderfactory;
import javax.swing.jcombobox;
import javax.swing.jcomponent;
import javax.swing.jframe;
import javax.swing.jlabel;
import javax.swing.jpanel;
import javax.swing.jradiobutton;
import javax.swing.jscrollpane;
import javax.swing.jtable;
import javax.swing.listselectionmodel;
import javax.swing.table.abstracttablemodel;
import javax.swing.table.tablecellrenderer;
import javax.swing.table.tablecolumn;
public class radiotable extends jpanel
{
private static final long serialversionuid = 1l;
private final boolean debug = true;
public radiotable ()
{
super (new borderlayout ());
jlabel type = new jlabel ("采集方式:");
jcombobox cbox1 = new jcombobox (new string[] { "方式一", "方式二" });
jlabel state = new jlabel ("采集状态:");
jcombobox cbox2 = new jcombobox (new string[] { "状态一", "状态二" });
jpanel top = new jpanel ();
top.add (type);
top.add (cbox1);
top.add (state);
top.add (cbox2);
add (top, borderlayout.north);
jtable table = new jtable (new model ());
table.setdefaultrenderer (jradiobutton.class, new tablecellrenderer ()
{
@override
public component gettablecellrenderercomponent ( jtable table, object radiobutton, boolean isselected,
boolean hasfocus, int row, int column )
{
jradiobutton newbutton = (jradiobutton) radiobutton;
newbutton.setselected (isselected);
tablecolumn tablecolumn = table.getcolumnmodel ().getcolumn (0);
tablecolumn.setresizable (false);
tablecolumn.setpreferredwidth (15);
newbutton.setborder (borderfactory.creatematteborder (0, 10, 0, 0, getbackground ()));
return newbutton;
}
});
table.setpreferredscrollableviewportsize (new dimension (500, 70));
table.setfillsviewportheight (true);
table.setselectionmode (listselectionmodel.single_selection);
jscrollpane scrollpane = new jscrollpane (table);
add (scrollpane, borderlayout.center);
}
class model extends abstracttablemodel
{
private static final long serialversionuid = 1l;
private string[] columnnames = { "选择", "实例编号", "采集模板", "数据源", "导出路径", "起始时间" };
private object[][] data = { { new jradiobutton (), 1, "223", "4", "1", new date () },
{ new jradiobutton (), 2, "23", "34", "224", new date () },
{ new jradiobutton (), 3, "水电费水电费", "23", "23", new date () },
{ new jradiobutton (), 4, "模板1", "数据源01", "导出路径", new date () } };
public int getcolumncount ()
{
return columnnames.length;
}
public int getrowcount ()
{
return data.length;
}
public string getcolumnname ( int col )
{
return columnnames[col];
}
public object getvalueat ( int row, int col )
{
return data[row][col];
}
public class extends object> getcolumnclass ( int c )
{
return getvalueat (0, c).getclass ();
}
public boolean iscelleditable ( int row, int col )
{
return false;
}
public void setvalueat ( object value, int row, int col )
{
if (debug)
{
system.out.println ("setting value at " + row + "," + col + " to " + value + " (an instance of "
+ value.getclass () + ")");
}
data[row][col] = value;
firetablecellupdated (row, col);
if (debug)
{
system.out.println ("new value of data:");
printdebugdata ();
}
}
private void printdebugdata ()
{
int numrows = getrowcount ();
int numcols = getcolumncount ();
for ( int i = 0; i < numrows; i++ )
{
system.out.print (" row " + i + ":");
for ( int j = 0; j < numcols; j++ )
{
system.out.print (" " + data[i][j]);
}
system.out.println ();
}
system.out.println ("--------------------------");
}
}
private static void createandshowgui ()
{
jframe frame = new jframe ("radiotable");
frame.setdefaultcloseoperation (jframe.exit_on_close);
jcomponent newcontentpane = new radiotable ();
newcontentpane.setopaque (true);
frame.setcontentpane (newcontentpane);
frame.pack ();
frame.setlocationrelativeto (null);
frame.setresizable (false);
frame.setvisible (true);
}
public static void main ( string[] args )
{
javax.swing.swingutilities.invokelater (new runnable ()
{
public void run ()
{
createandshowgui ();
}
});
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯