导航:首页 > 编程语言 > 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事件相关的资料

热点内容
橙啦英语app怎么查看时长 浏览:462
云管理服务器哪个好用 浏览:625
旷野之息安卓手机版怎么下载 浏览:53
杀手4怎么解压安装 浏览:234
pdf专业版破解版 浏览:139
jupyter能编译c程序吗 浏览:703
行军命令怎么下达 浏览:607
k9哪里查看删除的app 浏览:840
如何去找免单app 浏览:132
安卓机用久了卡了怎么清理垃圾 浏览:904
点点加密译 浏览:765
电信dns服务器怎么更改 浏览:710
命令与征服3玩不了 浏览:674
ubuntu命令行安装deb 浏览:65
物理文件夹与当前文件名相同 浏览:73
java接口协议 浏览:441
阿里巴巴要算法工程师吗 浏览:915
go二进制反编译 浏览:975
如何在xml中修改APP字体 浏览:998
编译程序就是把什么翻译成什么 浏览:944