📄 dbgrid.java
字号:
else
{
this.rows_show=this.rows_show_min;
this.set_option_visible(this.rows_show);
if(this.rows>this.rows_show)
this.sb.setVisible(true);
}
for (int j=0;j<this.cols;j++)
{
lab[0][j].setBackground(cell[0][j].Background);
lab[0][j].setForeground(cell[0][j].Foreground);
lab[0][j].setFont(cell[0][j].font);
lab[0][j].setText(cell[0][j].text);
lab[0][j].setAlignment(cell[0][j].Alignment);
//lab[0][j].reshape(swidth+30,sheight,this.colwidth[j],this.common_rowheight);
lab[0][j].setLocation(swidth+30,sheight);
lab[0][j].resize(this.colwidth[j],this.common_rowheight);
swidth+=this.colwidth[j];
}
//this.width=swidth;
for (int i=1;i<this.rows_show;i++)
{
sheight+=this.common_rowheight;
swidth=0;
for (int j=0;j<this.cols;j++)
{
lab[i][j].setBackground(cell[this.toprow+i-1][j].Background);
lab[i][j].setForeground(cell[this.toprow+i-1][j].Foreground);
lab[i][j].setFont(cell[this.toprow+i-1][j].font);
lab[i][j].setText(cell[this.toprow+i-1][j].text);
lab[i][j].setAlignment(cell[this.toprow+i-1][j].Alignment);
//lab[i][j].reshape(swidth+30,sheight,this.colwidth[j],this.common_rowheight);
lab[i][j].setLocation(swidth+30,sheight);
lab[i][j].resize(this.colwidth[j],this.common_rowheight);
if(this.cell[this.toprow+i-1][j].b_img)
{
//Image img_buf=createImage(this.lab[i][j].getSize().width,this.lab[i][j].getSize().height);
//Graphics offg=img_buf.getGraphics();
//offg.drawImage(this.cell[this.toprow+i-1][j].img,0,(int)(this.cell[this.toprow+i-1][j].height*(1.0-this.cell[this.toprow+i-1][j].rate_h)/2),(int)(this.cell[this.toprow+i-1][j].width*this.cell[this.toprow+i-1][j].rate_w),(int)(this.cell[this.toprow+i-1][j].height*this.cell[this.toprow+i-1][j].rate_h),this);
//this.lab[i][j].getGraphics().drawImage(img_buf,0,0,this);
try{
this.lab[i][j].getGraphics().drawImage(this.cell[this.toprow+i-1][j].img,0,(int)(this.cell[this.toprow+i-1][j].height*(1.0-this.cell[this.toprow+i-1][j].rate_h)/2),(int)(this.cell[this.toprow+i-1][j].width*this.cell[this.toprow+i-1][j].rate_w),(int)(this.cell[this.toprow+i-1][j].height*this.cell[this.toprow+i-1][j].rate_h),this);
}
catch (Exception e){}
}
swidth+=this.colwidth[j];
}
}
if(this.b_max)
this.width=this.width_max;
else
this.width=this.width0;
this.height=this.rows_show*this.common_rowheight;
this.sb.setMaximum(this.rows-this.rows_show+2);
this.sb.setLocation(this.width-20,0);
this.sb.resize(20,this.height);
this.sb.repaint();
}//end build
public void check_selected()
{this.row_clicked=0;
for(int i=1;i<this.rows_show;i++)
{
if(this.option[i].getState())
this.row_clicked=this.toprow+i-1;
}
}
public void append(int rows_add)
{
int lastrows;
lastrows=this.rows;
this.rows+=rows_add;
this.sb.setMaximum(this.rows-this.rows_show+2);
this.sb.repaint();
for(int i=lastrows;i<this.rows;i++)
for(int j=0;j<this.cols;j++)
cell[i][j]=new Cell("");
for(int i=0;i<this.cols;i++)
for (int j=lastrows;j<this.rows;j++)
{
this.cell[j][i].width=this.common_colwidth;
this.cell[j][i].Alignment=this.colAlignment[i];
}
for(int i=lastrows;i<this.rows;i++)
{
this.rowheight[i]=this.common_rowheight;
for (int j=0;j<this.cols;j++)
{
this.cell[i][j].font=this.font;
this.cell[i][j].height=this.common_rowheight;
this.cell[i][j].Background=this.Background;
this.cell[i][j].Foreground=this.Foreground;
}
this.set_option_invisible();
this.sb.setVisible(true);
}
//this.refresh();
}
public void Clear()
{ if(this.b_max)
this.zoomup();
for (int i=1;i<this.rows;i++)
for(int j=0;j<this.cols;j++)
{
this.cell[i][j].setBackground(this.Background);
this.cell[i][j].setForeground(this.Foreground);
this.cell[i][j].setAlignment(0);
this.cell[i][j].setText("");
this.cell[i][j].b_img=false;
}
this.rows=this.rows_show;
this.toprow=1;
this.row_clicked=0;
this.option[0].setState(true);
//this.set_option_invisible();
this.sb.setVisible(false);
this.refresh();
}
public void ClearAll()
{
if(this.b_max)
this.zoomup();
for (int i=0;i<this.rows;i++)
for(int j=0;j<this.cols;j++)
{
this.cell[i][j].setBackground(this.Background);
this.cell[i][j].setForeground(this.Foreground);
this.cell[i][j].setAlignment(0);
this.cell[i][j].setText("");
this.cell[i][j].b_img=false;
}
this.rows=this.rows_show;
this.toprow=1;
this.row_clicked=0;
this.option[0].setState(true);
this.sb.setVisible(false);
this.refresh();
}
public void mouseClicked(MouseEvent ev){
}
public void mouseReleased(MouseEvent ev){
}
public void mouseEntered(MouseEvent ev){
}
public void mouseExited(MouseEvent ev){
}
public void mousePressed(MouseEvent ev){
}
public boolean handleEvent(Event ev)
{
if (ev.target==sb)
{
switch(ev.id){
case Event.SCROLL_ABSOLUTE:
//System.out.println("moved");
this.toprow=this.sb.getValue();
//this.row_clicked=0;
//this.option[0].setState(true);
this.refresh();
break;
case Event.SCROLL_LINE_DOWN:
//System.out.println("scrolled down");
if (this.toprow<this.rows-this.rows_show)
{
this.toprow++;
//this.row_clicked=0;
//this.option[0].setState(true);
this.refresh();
}
break;
case Event.SCROLL_LINE_UP:
//System.out.println("scrolled up");
if (this.toprow>1)
{
this.toprow--;
//this.row_clicked=0;
//this.option[0].setState(true);
this.refresh();
}
break;
case Event.SCROLL_PAGE_DOWN:
//System.out.println("paged down");
if (this.toprow<this.rows-2*this.rows_show)
this.toprow=this.toprow+this.rows_show-1;
else
{
this.toprow=this.rows-this.rows_show;
this.sb.setValue(this.rows-this.rows_show+2);
}
//this.toprow=this.rows;
//this.row_clicked=0;
//this.option[0].setState(true);
this.refresh();
break;
case Event.SCROLL_PAGE_UP:
//System.out.println("paged up");
if (this.toprow>this.rows_show-1)
this.toprow=this.toprow-this.rows_show+1;
else
{
this.toprow=1;
this.sb.setValue(0);
}
//this.row_clicked=0;
//this.option[0].setState(true);
this.refresh();
break;
}
//return false;
return true;
}
return false;
}//end handleEvent
public void set_option_invisible()
{
for (int i=0;i<this.rows_show;i++)
{
this.option[i].setVisible(false);
this.option[i].repaint();
}
}
public void set_option_visible(int sum)
{ if (sum>this.rows_show)
sum=this.rows_show;
for (int i=1;i<sum;i++){
this.option[i].setVisible(true);
this.option[i].repaint();
}
}
public void zoomup()
{ if (this.b_max)
{
this.b_max=false;
//this.reshape(0,490,550,110);
this.setLocation(this.pLocation.x,this.pLocation.y);
this.refresh();
this.resize(this.width_size,this.height);
}
else
//if(!(this.rows==this.rows_show))
{ this.pLocation=this.getLocation();
this.width_size=this.getSize().width;
//this.width_max=590;
this.b_max=true;
int y=this.location().y;
this.rows_show=Math.min(this.rows,this.rows_show_max);
this.height=this.rows_show*this.common_rowheight;
int rows_up=this.rows_show-this.rows_show_min;
int i=y-rows_up*this.common_rowheight;
{
this.setLocation(0,i);
this.resize(this.width_max,this.height);
}
this.toprow=1;
this.row_clicked=0;
if(this.rows<this.rows_show_max)
this.sb.setVisible(false);
this.option[0].setState(true);
this.refresh();
}
this.sb.setValue(0);
}//end zoomup
}//end class dbGrid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -