在带有2个JFrame的Jtextfield中显示来自JTable的数据 [英] Show data from JTable in Jtextfield with 2 JFrames
问题描述
我正在为学校制作程序.
I am making a program for school.
我的程序有两个JFrame 第一个Jframe = Basisscherm 第二个Jframe = Toetsenbord
My program has two JFrame's The first Jframe = Basisscherm The second Jframe = Toetsenbord
在Jframe基础上,我得到了一个Jtable,其中填充了MYSQL数据库中的数据.此表显示标签,并且带有标签的是特定文本,因此每个标签都有自己的文本,它们位于同一数据库中
On the Jframe basisscherm i've got a Jtable filled with data from MYSQL Database. This Table showing labels and with this labels are specific text so each label has his own text this is in the same data base
现在在Jframe toetsenbord上,我有一个名称为Tekst的Jtextfield
Now on the Jframe toetsenbord i've got a Jtextfield with the name: Tekst
现在我的问题是我想通过从jtable中选择标签并单击确定"按钮来显示jtextfield中的文本,但是我现在不知道从何处开始
Now my problem is i want to show the text in the jtextfield by selecting the label from the jtable and clicking on a ok button but i don't now where to start
推荐答案
看看这个.使用它可以在JTable中获取选定的文本.
Have a look at this. using which you can get the selected text in JTable.
JTable table = new JTable();
if (table.getColumnSelectionAllowed()
&& !table.getRowSelectionAllowed()) {
// Column selection is enabled
// Get the indices of the selected columns
int[] vColIndices = table.getSelectedColumns();
} else if (!table.getColumnSelectionAllowed()
&& table.getRowSelectionAllowed()) {
// Row selection is enabled
// Get the indices of the selected rows
int[] rowIndices = table.getSelectedRows();
} else if (table.getCellSelectionEnabled()) {
// Individual cell selection is enabled
// In SINGLE_SELECTION mode, the selected cell can be retrieved using
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
int rowIndex = table.getSelectedRow();
int colIndex = table.getSelectedColumn();
// In the other modes, the set of selected cells can be retrieved using
table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
// Get the min and max ranges of selected cells
int rowIndexStart = table.getSelectedRow();
int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex();
int colIndexStart = table.getSelectedColumn();
int colIndexEnd = table.getColumnModel().getSelectionModel()
.getMaxSelectionIndex();
// Check each cell in the range
for (int r=rowIndexStart; r<=rowIndexEnd; r++) {
for (int c=colIndexStart; c<=colIndexEnd; c++) {
if (table.isCellSelected(r, c)) {
// cell is selected
}
}
}
}
这篇关于在带有2个JFrame的Jtextfield中显示来自JTable的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!