Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计 » Swing  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
话题被移动
该话题已被移动 - Biubiu , 2002-12-12 15:48
如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 swing中table的使用问题:要验证用户输入的数据
九佰



版主


发贴: 983
积分: 126
于 2002-12-12 11:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
swing : table是DefaultTableModel的实例,其中的行包括String类型、Boolean类型、Integer类型和Vector类型。要验证用户在table中输入的内容,怎么能使用键盘事件处理?有其他的方法吗?


作者 CellEditor [Re:九佰]
snowbug



CJSDN高级会员


发贴: 418
积分: 130
于 2002-12-12 13:27 user profilesend a private message to usersend email to snowbugsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Provide a CellEditor class.

Sun's tutorial on JTable, this will cover most of the JTable usage:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html



作者 Re:swing中table的使用问题:要验证用户输入的数据 [Re:九佰]
九佰



版主


发贴: 983
积分: 126
于 2002-12-12 14:23 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看过了,都是简单的应用。



http://www.teamlet.org

海纳百川,有容乃大
壁立千仞,无欲则刚
智者不惑,勇者无惧
止戈为武,仁者无敌
作者 EX:1 [Re:九佰]
scottlai



元老


发贴: 451
积分: 366
于 2002-12-12 15:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
package game.roulette.admin;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public class AdminResultCellEditor extends JToggleButton implements TableCellEditor, ItemListener
{
  Vector listener = new Vector();
  Font fontEnabled = new java.awt.Font("Serif", Font.BOLD|Font.ITALIC, 18);
  Font fontDisabled= new java.awt.Font("Serif", Font.PLAIN, 18);

  public AdminResultCellEditor()
  {
    setFocusPainted(false);
//    setFont(new java.awt.Font("Serif", Font.BOLD, 20));
    addItemListener(this);
  }

  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
  {
    AdminResultCell cell;

    if(value instanceof AdminResultCell)
    {
      cell = (AdminResultCell)value;
      setSelected(cell.isSelected());
      setText(cell.getText());

//      setEnabled(cell.isEnabled());
//      setBackground(cell.getColor());
//      setForeground(Color.white);

      if(cell.isEnabled())
      setFont(fontEnabled);
      else
      setFont(fontDisabled);

      setForeground(cell.getColor());

      return this;
    }
    else
    return null;
  }

  public Object getCellEditorValue()
  {
    return this;
  }

  public boolean isCellEditable(EventObject anEvent)
  {
    return true;
  }

  public boolean shouldSelectCell(EventObject anEvent)
  {
    return true;
  }

  public boolean stopCellEditing()
  {
    return true;
  }

  public void cancelCellEditing()
  {
    return;
  }

  public void addCellEditorListener(CellEditorListener l)
  {
    listener.add(l);
  }

  public void removeCellEditorListener(CellEditorListener l)
  {
    listener.remove(l);
  }

  public void itemStateChanged(ItemEvent e)
  {
    CellEditorListener l;

    for(int i=0; i<listener.size(); i++)
    {
      l = (CellEditorListener)listener.getLight Bulb;
      l.editingStopped(changeEvent);
    }
  }
}



作者 CONTINUE [Re:scottlai]
scottlai



元老


发贴: 451
积分: 366
于 2002-12-12 15:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class AdminResultCellEditor extends JToggleButton


作者 CONTINUE 1 [Re:scottlai]
scottlai



元老


发贴: 451
积分: 366
于 2002-12-12 15:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
{
AdminResultCell cell;

if(value instanceof AdminResultCell)
{
cell = (AdminResultCell)value;
setSelected(cell.isSelected());
setText(cell.getText());

// setEnabled(cell.isEnabled());
// setBackground(cell.getColor());
// setForeground(Color.white);

if(cell.isEnabled())
setFont(fontEnabled);
else
setFont(fontDisabled);

setForeground(cell.getColor());

return this;
}
else
return null;
}



作者 Re:swing中table的使用问题:要验证用户输入的数据 [Re:九佰]
Biubiu

Pure Java

总版主


发贴: 471
积分: 50
于 2002-12-12 15:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最好还是使用模态对话框实现编辑功能。框架做的好的话,这个对话框可以自动生成。仅供参考。


In theory, there is no difference between theory and practice; in practice, however, there is.

If the only tool you have is a hammer, you tend to see every problem as a nail.
作者 CONTINUE 2 [Re:scottlai]
scottlai



元老


发贴: 451
积分: 366
于 2002-12-12 15:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
tableCurrent.setDefaultEditor(AdminResultCell.class,adminResultCellEditor);


作者 CONTINUE 3 [Re:scottlai]
scottlai



元老


发贴: 451
积分: 366
于 2002-12-12 15:55 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class AdminResultCellEditor extends JToggleButton
因為 AdminResultCellEditor extends JToggleButton &   
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
  {
    AdminResultCell cell;

    if(value instanceof AdminResultCell)
    {
      cell = (AdminResultCell)value;
      setSelected(cell.isSelected());
      setText(cell.getText());

//      setEnabled(cell.isEnabled());
//      setBackground(cell.getColor());
//      setForeground(Color.white);

      if(cell.isEnabled())
      setFont(fontEnabled);
      else
      setFont(fontDisabled);

      setForeground(cell.getColor());

      return this;
^^^^^^^^
SO ADD LISTENER TO AdminResultCellEditor



作者 CONTINUE 4 [Re:scottlai]
scottlai



元老


发贴: 451
积分: 366
于 2002-12-12 15:56 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
OVER~



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923