- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在这篇文章中 Making Table With List Of JPanels我可以制作一个包含面板列表的表格。这张表有很多功能,但我需要一个新功能,它正在应用百分比列。这意味着我喜欢所有列的宽度不等于并且用 float 数组确定。
这是我的类(class)表:
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;
public class PanelTable extends JPanel {
private String data[][];
private String columns[];
private int numberOfRows;
private int numberOfColumns;
private JTextArea[] header;
private JTextArea[][] cell;
public PanelTable(String data[][], String columns[]) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.data = data;
this.columns = columns;
numberOfRows = data.length;
numberOfColumns = columns.length;
makeHeader();
makeCells();
}
public void makeCells() {
cell = new JTextArea[numberOfRows][numberOfColumns];
for (int rowIndex = 0; rowIndex < numberOfRows; rowIndex++) {
add(getRow(numberOfColumns, rowIndex));
}
}
public void makeHeader() {
header = new JTextArea[numberOfColumns];
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
JTextArea ta = new JTextArea();
ta.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
ta.setBackground(new Color(57, 77, 112));
ta.setForeground(Color.WHITE);
ta.setText(columns[columnIndex]);
ta.setFont(new Font("Calibri Light", Font.BOLD, 25));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
header[columnIndex] = ta;
}
JPanel rowHeader = new JPanel();
rowHeader.setLayout(new BoxLayout(rowHeader, BoxLayout.X_AXIS));
for (int i = 0; i < numberOfColumns; i++) {
rowHeader.add(header[i]);
}
add(rowHeader);
}
public Component getRow(int numberOfColumns, int rowIndex) {
JPanel row = new JPanel();
//use GridLayout if you want equally spaced columns
row.setLayout(new BoxLayout(row, BoxLayout.X_AXIS));
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
row.add(getCell(rowIndex, columnIndex));
}
return row;
}
public Component getCell(int rowIndex, int columnIndex) {
if (cell[rowIndex][columnIndex] == null) {
JTextArea ta = new JTextArea();
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
ta.setSize(50, ta.getHeight());
ta.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
ta.setBorder(BorderFactory.createLineBorder(Color.BLACK));
ta.setText(data[rowIndex][columnIndex]);
ta.setFont(new Font("Bmitra", Font.BOLD, 15));
cell[rowIndex][columnIndex] = ta;
}
return cell[rowIndex][columnIndex];
}
}
这是一个用于测试的 gui 示例:
import javax.swing.*;
import java.awt.*;
public class GUI extends JFrame {
private PanelTable table;
private JScrollPane scrollPane;
public GUI(){
super("Bank Table");
JPanel contentPanel = new JPanel();
setContentPane(contentPanel);
contentPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
setLayout(new BorderLayout());
setMinimumSize(new Dimension(1000,700));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[][] data= new String[][]{{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/01"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/02"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/03"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/04"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/05"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/06"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/07"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/08"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/09"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/10"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/11"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/12"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/13"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/14"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/15"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/16"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/17"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/18"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/19"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/20"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/21"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/22"},
{"0212670003009", "ص 318", "77081634","3800ddddddddddddddddddddddddddddddddddddddddd0000","0","331142","2102","وصول چک","08:56:46","1397/05/23"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/24"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/25"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/26"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/15"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/16"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/17"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/18"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/19"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/20"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/21"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/22"},
{"0212670003009", "ص 318", "77081634","3800ddddddddddddddddddddddddddddddddddddddddd0000","0","331142","2102","وصول چک","08:56:46","1397/05/23"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/24"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/25"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/26"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/15"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/16"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/17"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/18"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/19"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/20"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/21"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/22"},
{"0212670003009", "ص 318", "77081634","3800ddddddddddddddddddddddddddddddddddddddddd0000","0","331142","2102","وصول چک","08:56:46","1397/05/23"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/24"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/25"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/26"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/15"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/16"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/17"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/18"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/19"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/20"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/21"},
{"0212670003009", "ص 318", "77081634","380dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000","0","331142","2102","وصول چک","08:56:46","1397/05/22"},
{"0212670003009", "ص 318", "77081634","3800ddddddddddddddddddddddddddddddddddddddddd0000","0","331142","2102","وصول چک","08:56:46","1397/05/23"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/24"},
{"0212670003009", "ص 318", "77081634","38000ddddddddddddddddddddddddddddddddddddddd000","0","331142","2102","وصول چک","08:56:46","1397/05/25"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/26"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/27"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/28"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/29"},
{"0212670003009", "ص 318", "77081634","38000000","0","331142","2102","وصول چک","08:56:46","1397/05/30"}};
String[] columns= new String[]{"ستون ۲", "ستون ۱", "ستون ۱۰","ستون ۹","ستون ۸","ستون ۷","ستون ۶","ستون ۵","ستون ۴","ستون ۳"};
PanelTable table = new PanelTable(data,columns);
scrollPane = new JScrollPane(table);
scrollPane.getVerticalScrollBar().setUnitIncrement(50);
add(scrollPane,BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[]){
GUI gui =new GUI();
}
}
最佳答案
这样做:首先创建一个宽度大小的数组。例如:
final int[] columnsWidth = { 300, 100, 50, 300, 50 };
然后在您的方法 makeHeader 和 getCell 中设置文本区域的所有属性,同时设置首选大小。请参阅下面的代码。这应该为您提供基于大小数组的宽度。
ta.setPreferredSize(new Dimension(columnsWidth[columnIndex], ta.getHeight()));
让我知道它是否适合你:)
完整代码如下:对于图形用户界面:
import javax.swing.*;
import java.awt.*;
public class GUI extends JFrame {
private PanelTable2 table;
private JScrollPane scrollPane;
public GUI(){
super("Bank Table");
JPanel contentPanel = new JPanel();
setContentPane(contentPanel);
contentPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
setLayout(new BorderLayout());
setMinimumSize(new Dimension(1000,700));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final String[] columns = { "Big Column", "Serodys", "Ramírez", "Entrada", "MercaSur" };
final String[][] data = {{"2323", "Hundreds","2323", "Hundreds","2323"},{"2323", "Hundreds","2323", "Hundreds","2323"}};
// final PanelTable22 panel = new PanelTable22(data, columns);
System.out.println("Hey");
PanelTable2 table = new PanelTable2(data,columns);
System.out.println("!!!");
scrollPane = new JScrollPane(table);
scrollPane.getVerticalScrollBar().setUnitIncrement(50);
add(scrollPane,BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[]){
GUI gui =new GUI();
}
}
对于表格模型:
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class PanelTable2 extends JPanel {
private String data[][];
private String columns[];
private int numberOfRows;
private int numberOfColumns;
private JTextArea[] header;
private JTextArea[][] cell;
final int[] columnsWidth = { 300, 100, 50, 300, 50 };
public PanelTable2(String data[][], String columns[]) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.data = data;
this.columns = columns;
numberOfRows = data.length;
numberOfColumns = columns.length;
makeHeader();
makeCells();
}
public void makeCells() {
cell = new JTextArea[numberOfRows][numberOfColumns];
for (int rowIndex = 0; rowIndex < numberOfRows; rowIndex++) {
add(getRow(numberOfColumns, rowIndex));
}
}
public void makeHeader() {
header = new JTextArea[numberOfColumns];
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
JTextArea ta = new JTextArea();
ta.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
ta.setPreferredSize(new Dimension(columnsWidth[columnIndex], ta.getHeight()));
ta.setBackground(new Color(57, 77, 112));
ta.setForeground(Color.WHITE);
ta.setText(columns[columnIndex]);
ta.setFont(new Font("Calibri Light", Font.BOLD, 25));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
header[columnIndex] = ta;
}
JPanel rowHeader = new JPanel();
rowHeader.setLayout(new BoxLayout(rowHeader, BoxLayout.X_AXIS));
for (int i = 0; i < numberOfColumns; i++) {
rowHeader.add(header[i]);
}
add(rowHeader);
}
public Component getRow(int numberOfColumns, int rowIndex) {
JPanel row = new JPanel();
//use GridLayout if you want equally spaced columns
row.setLayout(new BoxLayout(row, BoxLayout.X_AXIS));
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
row.add(getCell(rowIndex, columnIndex));
}
return row;
}
public Component getCell(int rowIndex, int columnIndex) {
if (cell[rowIndex][columnIndex] == null) {
JTextArea ta = new JTextArea();
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
ta.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
ta.setBorder(BorderFactory.createLineBorder(Color.BLACK));
ta.setText(data[rowIndex][columnIndex]);
ta.setFont(new Font("Bmitra", Font.BOLD, 15));
ta.setPreferredSize(new Dimension(columnsWidth[columnIndex], ta.getHeight()));
cell[rowIndex][columnIndex] = ta;
}
return cell[rowIndex][columnIndex];
}
}
关于java - 使用 JPanels 列表制作表格(使用百分比大小列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51879830/
好的,这听起来很简单,但我已经花了几个小时在谷歌上搜索,我只是找不到解决方案,这并不复杂。 我想创建一个包含图像和文本的表格。我希望表格的每一行都具有相同的高度。我希望文本始终从顶部开始。 IE。 \
在我的网站表单上 - 我的出生日期、月份和年份菜单显示在两行上,我希望它们都显示在同一行上。 当我测试代码时,它显示在一行中,所以我相信一定存在宽度问题。 您可以在右侧表格 (incomeprotec
我们需要跟踪和审核生产,本质上我们有很多订单,但我们似乎在途中丢失了一些产品(废品等)。 为了阻止这种情况,我们现在已在 Google 表格上下了订单,并列出了应有的数量,然后员工会写下收到的数量。
我正在转换我的应用程序,以便它适用于 iOS 7。在应用程序的一部分,我有两个搜索栏,每个搜索栏都有一个与之关联的 UISearchDisplayController。当我搜索 UISearchDis
正如标题所说,非固定表格布局是否与类似的 HTML 表格具有相同的性能问题? 最佳答案 非固定表格的问题在于,要确定一列的宽度,必须加载该列的所有单元格。这仅在...... …您有一个包含几千字节或几
我在使用 Javascript 遍历表格并从一行的第一个单元格获取文本时遇到问题。我想获取此单元格的文本,以便我可以将它与其他内容进行比较,如果文本匹配则删除该行。但是,当我尝试获取文本时,实际出现的
我经常发现自己想要制作一个表格表格——一堆行,每一行都是一个单独的表格,有自己的字段和提交按钮。例如,这是一个宠物店应用程序示例——假设这是一个结帐屏幕,您可以选择更新所选宠物的数量和属性,并在结帐前
看过许多UBB代码,包括JS,ASP,JSP的,一直没发现表格的UBB,虽然可以直接用HTML模式实现相同表格功能,但对于某些开放的站点来说开放HTML模式终究是不合适的,故一直想实现表格的UBB。
表格由 table 标签来定义。每个表格均有若干行(由 tr 标签定义),每行被分割为若干单元格(由 td 标签定义)。字母 td 指表格数据(table data),即数据单元格的内容。数据单元格
我有一个 HTML 与 border-radius和使用 position: sticky 的粘性标题看起来像这样: https://codepen.io/muhammadrehansaeed/pen
对于 iPhone 应用程序,我需要以网格格式显示只读表格数据。该数据可能有许多行和列。 我可以使用 UITableView,但问题是数据很可能会非常宽并且需要滚动。 有没有办法将 UITableVi
我知道这里有类似的问题,但我找不到适合我的答案。 我想要的是显示表单“默认”是选择了某些选项(在这种情况下,除了“Ban Appeal”或“Ban Appeal(西类牙语)”之外的所有内容,我希望仅在
天啊! 我想在Flutter中创建以下非常简单的表。基本上是两列文字,左列右对齐,右列左对齐。如果右列具有多个名称,则每一行都将顶部对齐。 左列应自动调整为最大项目的大小(因为每个标题都有翻译字符串)
我们开始构建 SSAS 表格模型,并想知道大多数人是否拥有一个或多个模型。如果有多个,您是否复制每个所需的表,或者是否有办法在模型之间共享表?我想我知道答案,但我希望那些有更多经验的人能够证实我们的发
tl;博士 如何将任意数量的单词分成两列,总是在最后一列中只有最后一个单词,在第一列中包含所有其他单词? =IFS( LEN(C2)-LEN(SUBSTITUTE(C2," ",""))=1, SP
你们知道一个图表或dable,它可以提供一个简短而简洁但仍然完整且相对最新的现有协议(protocol)及其细节的 View ? (即:ZeroMQ、Rendez-Vous、EMS、...所有这些!:
我才刚刚开始开发MFC应用程序,我希望对整个“控件”概念更加熟悉。我在Visual Studio中使用对话框编辑器,到目前为止,我无法找到添加简单表/网格的功能。这对我来说似乎很基础,但是我什至找不到
我需要对一个非常大的表或矩阵执行计算和操作,大约有 7500 行和 30000 列。 矩阵数据将如下所示: 文件编号|字1 |字 2 |字 3 |... |字 30000 |文档类 0032 1 0
我正在使用设计非常糟糕的数据库,我需要在编写查询之前重新调整表格。 以下是我的常见问题: 时间戳已分为两列(一列用于日期,另一列用于时间)。 一些字符串列也被拆分成多个列。 大多数字符串都有固定长度和
我正在尝试显示 $row["name"] 通过 HTML Table 的形式,如下所示: echo " ".$row["name"]." "; 我也从这里获取行变量: $que
我是一名优秀的程序员,十分优秀!