导航:首页 > 编程语言 > javaweb事件

javaweb事件

发布时间:2025-05-20 23:16:16

java web 怎么在jtable中添加按钮

java web在jtable中添加按钮的示例如下:

importjava.awt.BorderLayout;
importjava.awt.Color;
importjava.awt.Component;
importjava.awt.Dimension;
importjava.awt.event.MouseAdapter;
importjava.awt.event.MouseEvent;
importjava.io.File;

importjavax.swing.BorderFactory;
importjavax.swing.ImageIcon;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
importjavax.swing.JScrollPane;
importjavax.swing.JTable;
importjavax.swing.UIManager;
importjavax.swing.border.Border;
importjavax.swing.border.EmptyBorder;
importjavax.swing.table.AbstractTableModel;
importjavax.swing.table.TableCellRenderer;

{
privateJTabletable;
privateJScrollPanescrollPane;
privateJButton[]buttons;
privateStringpath=System.getProperty("user.dir")+File.separator
+"images"+File.separator;

publicJTableButton(){
setBorder(BorderFactory.createLineBorder(Color.red,1));
init();
}

privatevoidinit(){
StringheadName[]={"Name","age","sex","adress","image"};

buttons=newJButton[5];
for(inti=0;i<buttons.length;i++){
buttons[i]=newJButton(""+i);
}
Objectobj[][]={
{"LiMing",23,Boolean.TRUE,buttons[0],
newImageIcon(path+"icon.png")},
{"ZhangSan",25,Boolean.TRUE,buttons[1],
newImageIcon(path+"icon.png")},
{"WangWu",21,Boolean.FALSE,buttons[2],
newImageIcon(path+"icon.png")},
{"LiSi",28,Boolean.TRUE,buttons[3],
newImageIcon(path+"icon.png")},
{"LuBo",20,Boolean.FALSE,buttons[4],
newImageIcon(path+"icon.png")},};

table=newJTable(newMyTableModel(headName,obj));
table.setDefaultRenderer(JButton.class,newComboBoxCellRenderer());
scrollPane=newJScrollPane(table);
setLayout(newBorderLayout());
add(scrollPane,BorderLayout.CENTER);
addHandler();
}
privatevoidaddHandler(){
//添加事件
table.addMouseListener(newMouseAdapter(){
publicvoidmouseClicked(MouseEvente){
System.out.println("table");
introw=table.getSelectedRow();
intcolumn=table.getSelectedColumn();
System.out.println("row="+row+":"+"column="+column);
if(column==3){
//处理button事件写在这里...
System.out.println(((JButton)table.getValueAt(row,column)).getText());
}
}
});
}
publicstaticvoidmain(String[]args){
JFrameframe=newJFrame();
frame.add(newJTableButton());
frame.setSize(newDimension(800,400));
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
{
privateStringheadName[];
privateObjectobj[][];

publicMyTableModel(){
super();
}

publicMyTableModel(String[]headName,Object[][]obj){
this();
this.headName=headName;
this.obj=obj;
}

publicintgetColumnCount(){
returnheadName.length;
}

publicintgetRowCount(){
returnobj.length;
}

publicObjectgetValueAt(intr,intc){
returnobj[r][c];
}

publicStringgetColumnName(intc){
returnheadName[c];
}

publicClass<?>getColumnClass(intcolumnIndex){
returnobj[0][columnIndex].getClass();
}

@Override
publicbooleanisCellEditable(introwIndex,intcolumnIndex){
if(columnIndex==3||columnIndex==4){
returnfalse;
}
returntrue;
}

}
}

{
(JTabletable,Objectvalue,
booleanisSelected,booleanhasFocus,introw,intcolumn){
JButtoncmb=(JButton)value;
if(isSelected){
cmb.setForeground(table.getSelectionForeground());
cmb.setBackground(table.getSelectionBackground());
}else{
cmb
.setForeground((unselectedForeground!=null)?unselectedForeground
:table.getForeground());
cmb
.setBackground((unselectedBackground!=null)?unselectedBackground
:table.getBackground());
}
cmb.setFont(table.getFont());
if(hasFocus){
cmb
.setBorder(UIManager
.getBorder("Table.focusCellHighlightBorder"));
if(!isSelected&&table.isCellEditable(row,column)){
Colorcol;
col=UIManager.getColor("Table.focusCellForeground");
if(col!=null){
cmb.setForeground(col);
}
col=UIManager.getColor("Table.focusCellBackground");
if(col!=null){
cmb.setBackground(col);
}
}
}else{
cmb.setBorder(noFocusBorder);
}
returncmb;
}

=newEmptyBorder(1,1,1,1);

;
;
}

❷ javaweb鼠标移到内容上自动出现一个小界面

1、给目标javaweb绑定onmouseover,onmouseout事件,弹出一个窗口用div+背景图片的方法,自己控制样式。
2、当鼠标放在.navli上时,把subpage内的li全部隐藏,然后再把相应id的li显示出来就行了,就不会出现一个小界面了。

阅读全文

与javaweb事件相关的资料

热点内容
单片机学习指导 浏览:586
胸7椎体轻度压缩 浏览:108
sk5服务器什么意思 浏览:554
什么是廊坊交警app 浏览:294
衣柜造价算法 浏览:984
默认的web服务器地址 浏览:694
单片机与发光二极管 浏览:320
pythonwebmodule 浏览:328
空调压缩机不停了 浏览:115
python序列怎么取 浏览:199
线上数据库加密怎么查询 浏览:794
js中数据加密 浏览:470
穴pdf 浏览:549
阿里云服务器云数据库还需要吗 浏览:146
在程序设计中常用的算法有哪些 浏览:977
为什么苏州公积金app一直维护 浏览:805
有ip地址但是dhcp服务器 浏览:446
三星手机加密中断怎么回事 浏览:538
训练模型init源码 浏览:840
程序编译是谁的功能 浏览:505