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

熱點內容
python3入門指南 瀏覽:684
php保存圖片路徑 瀏覽:721
python通過搜索抓取網站 瀏覽:514
程序員代碼惡搞500次 瀏覽:575
伺服器白名單命令 瀏覽:90
小米手機里壓縮包是什麼能刪除么 瀏覽:144
如何使cmake交叉編譯安卓 瀏覽:812
佳明手錶怎麼關閉app 瀏覽:242
php合並數組為字元串 瀏覽:67
指上解壓 瀏覽:244
橙啦英語app怎麼查看時長 瀏覽:462
雲管理伺服器哪個好用 瀏覽:625
曠野之息安卓手機版怎麼下載 瀏覽:53
殺手4怎麼解壓安裝 瀏覽:234
pdf專業版破解版 瀏覽:139
jupyter能編譯c程序嗎 瀏覽:703
行軍命令怎麼下達 瀏覽:607
k9哪裡查看刪除的app 瀏覽:840
如何去找免單app 瀏覽:132
安卓機用久了卡了怎麼清理垃圾 瀏覽:904