jntable.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 122 行
JAVA
122 行
package org.jnode.wt.components;
import java.awt.Color;
import java.awt.Font;
/**
* @author Kishore
*/
public class JNTable extends JNPanel {
/* These are ToggleButtons */
//private ArrayList rowHeaders = new ArrayList();
/* These are ToggleButtons */
//private ArrayList columnHeaders = new ArrayList();
private int[] columnHeadersWidth = null;
// For fixed Table values
private org.jnode.wt.components.JNComponent[][] cells = null;
//private int numberofRows = 1;
private int numberofColumns = 1;
// private int eachcompheight = 26;
private int eachcompheight = 32;
private int titleLabelHeight = 30;
/**
* JNTabble constructor comment.
*/
public JNTable(int r, int c) {
super();
__setRowCoumns(r, c);
init();
}
/*private void __add(String str, int r, int c) {
this.add(new JNLabel(str), r, c);
}*/
private void __setRowCoumns(int r, int c) {
//this.numberofRows = r;
this.numberofColumns = c;
cells = new org.jnode.wt.components.JNComponent[ r][ c];
columnHeadersWidth = new int[ c];
}
public void add(org.jnode.wt.components.JNComponent comp, int r, int c) {
cells[ r][ c] = comp;
int x = getXTillCoulumn(c);
int y = (r * eachcompheight) + titleLabelHeight;
comp.setLocation(x, y);
comp.setSize(columnHeadersWidth[ c], eachcompheight);
this.add(comp);
}
private int getXTillCoulumn(int c) {
int x = 0;
for (int i = 0; i < c; i++) {
x = x + columnHeadersWidth[ i];
}
return x;
}
private void init() {
// this.setBackground(Color.white);
this.setLayout(null);
}
public void setColumnTitle(String[] arr) {
int nextx = 0;
JNLabel lab = null;
for (int c = 0; c < numberofColumns; c++) {
lab = new JNLabel(arr[ c]);
//
lab.setAlignment(JNLabel.CENTER);
Font f = lab.getFont();
lab.setFont(new Font(f.getName(), Font.BOLD, f.getSize()));
lab.setBackground(Color.blue);
lab.setForeground(Color.white);
lab.setSize(lab.getPreferredSize());
//
lab.setLocation(nextx, 0);
this.add(lab);
nextx = nextx + lab.getWidth();
columnHeadersWidth[ c] = lab.getWidth();
}
titleLabelHeight = lab.getHeight();
}
// this method will be modified later.
/*private void setEachCellSize(int w, int h) {
org.jnode.wt.components.JNComponent comp = null;
for (int r = 0; r < numberofRows; r++) {
for (int c = 0; c < numberofColumns; c++) {
comp = cells[ r][ c];
if (comp != null) {
comp.setSize(w, h);
}
}
}
}*/
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?