導航:首頁 > 編程語言 > 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事件相關的資料

熱點內容
美國程序員生活 瀏覽:219
51單片機摘要 瀏覽:402
英語經典pdf下載 瀏覽:314
大學文件夾怎麼刪除 瀏覽:665
linux科研軟體 瀏覽:550
ue4打包編譯著色器 瀏覽:772
雲伺服器可以在手機上登錄嗎 瀏覽:673
網游腳本為什麼要連接伺服器 瀏覽:4
程序員發展路線圖 瀏覽:318
手機語音加密會議 瀏覽:587
冰與火pdf 瀏覽:416
為什麼叫我買阿里雲伺服器 瀏覽:470
加密貨幣征稅一覽表 瀏覽:959
llc編譯器 瀏覽:922
數控可編程電阻器 瀏覽:757
培訓app源碼 瀏覽:433
phpcurl啟用 瀏覽:535
ubuntu圖形編程 瀏覽:441
jar包啟動命令 瀏覽:680
java數組一維轉二維 瀏覽:500