在jsp当中,如何给一个添加了横向滚动条的table给固定列。

在jsp当中,如何给一个添加了横向滚动条的table给固定列。,第1张

我一般都不用TABLE标签,感觉很难控制,比如字多点就撑大了乱了。用一个带边框的DIV当成一格。用代码加加加,就是一个表了,想怎么控制就怎么控制,想要滚动条,就在外面套上一个DIV,设这个DIV的CSS,滚动条就出来了。

// TableFeature.java

// A test of the JTable class using default table models and a convenience

// constructor. Resizing and selection defaults are altered.

//

import java.awt.*

import javax.swing.*

import java.util.Date

import java.io.File

public class TableFeature extends JFrame {

String titles[] = new String[] {

"Directory?", "File Name", "Read?", "Write?", "Size", "Last Modified"

}

public TableFeature() {

super("Simple JTable Test")

setSize(300, 200)

setDefaultCloseOperation(EXIT_ON_CLOSE)

File pwd = new File(".")

Object[][] stats = getFileStats(pwd)

JTable jt = new JTable(stats, titles)

jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)

jt.setColumnSelectionAllowed(true)

JScrollPane jsp = new JScrollPane(jt)

getContentPane().add(jsp, BorderLayout.CENTER)

}

public Object[][] getFileStats(File dir) {

String files[] = dir.list()

Object[][] results = new Object[files.length][titles.length]

for (int i=0i <files.lengthi++) {

File tmp = new File(files[i])

results[i][0] = new Boolean(tmp.isDirectory())

results[i][1] = tmp.getName()

results[i][2] = new Boolean(tmp.canRead())

results[i][3] = new Boolean(tmp.canWrite())

results[i][4] = new Long(tmp.length())

results[i][5] = new Date(tmp.lastModified())

}

return results

}

public static void main(String args[]) {

TableFeature tf = new TableFeature()

tf.setVisible(true)

}

}

关键代码:jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)

<table align=center height=100%><tr><td>

<div style="width:200 height:200border:0

solid navyoverflow:auto">

<br><br><br><br><Br><br><BR><BR>

<br><br><br><br><br><br><br><br><br>

 

</div>

</td></tr></table>

下面是常用的颜色及式样代码

<style type="text/css">

<!--

BODY{

scrollbar-face-color:white

scrollbar-highlight-color:skyblue

scrollbar-shadow-color:skyblue

scrollbar-3dlight-color:white

scrollbar-arrow-color:skyblue

scrollbar-track-color:white

scrollbar-darkshadow-color:white}

-->

</style>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11844591.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存