Cell value spanning multiple rows in JTable
Hi,
I have a JTable where I want a single column value alone to span multiple rows.
Something like
Course No. | Location | Cost
| loc1 | 1000
1 ---------------------------------------------
| loc2 | 2000
How can I create a JTable like this?
Thanks for the help.
I have a link for that,
http://www2.gol.com/users/tame/
go in swing examples, JTable #4.
Hope it helps :)
Similar Messages
-
Split Single Cell Value to Multiple Rows
Uses: Oracle 9i;
There is this restriction in our country, where an individual cheque value can not exceed Rs. 100,000,000. We organize our Payment list for a settlement date and the sample data table looks like this:
PaymentID | AccountID | PaymentMode | PaymentDate | PaymentValue
=============================================
p1,ac1,cheque,01-Dec-2009,99,000;
p2,ac2,cheque,01-Dec-2009,789,772,984;
p3,ac3,cheque,01-Dec-2009,433,941,200;
p4,ac4,cheque,02-Dec-2009,199,900;
( row values are separated by commas )
ii.e Row No. 3 has a payment value of 433,941,200, so splitting them into 100 million blocks will need to create the following separate payments:
100,000,000
100,000,000
100,000,000
100,000,000
33,941,200
and will be inserted into the same table having different paymentID's. Is there anyway of solving the via SQL?
Regards,
Edited by: _hifni on Dec 17, 2009 2:42 PMHi,
You can do that by joining your table to a Counter Table that counts from 1 to the greatest number of checks needed.
This should give you some ideas:
VARIABLE MaxPerCheck NUMBER
EXEC :MaxPerCheck := 1e8;
WITH cntr AS
SELECT LEVEL AS n
, (LEVEL - 1) * :MaxPerCheck AS LowAmount
FROM dual
CONNECT BY LEVEL <= CEIL ( ( SELECT MAX (PaymentValue)
FROM table_x
/ :MaxPerCheck
SELECT x.PaymentID
, x.PaymentValue
, c.n
, LEAST ( x.PaymentValue - c.LowAmount
, :MaxPerCheck
) AS CheckAmount
FROM table_x x
JOIN cntr c ON x.PaymentValue > c.LowAmount
ORDER BY x.PaymentID
, c.n
;if you'd like to post CREATE TABLE and INSERT statements for your sample data, then I could test this. -
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
Concatenate a column value across multiple rows - PDW
We are using PDW based on SQL2014. We require an efficient logic on how to concatenate a column value across multiple rows. We have the following table
T1
(CompanyID, StateCD)
Having following rows:
1 NY
1 NJ
1 CT
2 MA
2 NJ
2 VA
3 FL
3 CA
We need a code snippet which will return following result set:
1
CT,NJ,NY
2
MA,NJ,VA
3
CA,FL
We have tried built-in function STUFF with FOR XML PATH clause and it is not supported in PDW. So, we need a fast alternative.Hi Try this:
SELECT * INTO #ABC
FROM
SELECT 1 AS ID,'NY' AS NAME
UNION
SELECT 1 AS ID,'NJ' AS NAME
UNION
SELECT 1 AS ID,'CT' AS NAME
UNION
SELECT 2 AS ID,'MA' AS NAME
UNION
SELECT 2 AS ID,'NJ' AS NAME
UNION
SELECT 2 AS ID,'VA' AS NAME
UNION
SELECT 3 AS ID,'FL' AS NAME
UNION
SELECT 3 AS ID,'CA' AS NAME
)A
CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800))
DECLARE @TMP VARCHAR(MAX),
@V_MIN INT,
@V_MAX INT,
@V_COUNT INT
SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC
SET @V_COUNT=@V_MIN
WHILE @V_COUNT<=@V_MAX
BEGIN
SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC
WHERE ID=@V_COUNT
INSERT INTO ##CDB (ID, NAME) SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME
SET @V_COUNT=@V_COUNT+1
END
SELECT * FROM ##CDB
OR
SELECT * INTO #ABC
FROM
SELECT 1 AS ID,'NY' AS NAME
UNION
SELECT 1 AS ID,'NJ' AS NAME
UNION
SELECT 1 AS ID,'CT' AS NAME
UNION
SELECT 2 AS ID,'MA' AS NAME
UNION
SELECT 2 AS ID,'NJ' AS NAME
UNION
SELECT 2 AS ID,'VA' AS NAME
UNION
SELECT 3 AS ID,'FL' AS NAME
UNION
SELECT 3 AS ID,'CA' AS NAME
UNION
SELECT 5 AS ID,'LG' AS NAME
UNION
SELECT 5 AS ID,'AP' AS NAME
)A
CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800))
DECLARE @TMP VARCHAR(MAX),
@V_MIN INT,
@V_MAX INT,
@V_COUNT INT
SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC
SET @V_COUNT=@V_MIN
WHILE @V_COUNT<=@V_MAX
BEGIN
SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC
WHERE ID=@V_COUNT
SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME INTO #TEMP
INSERT INTO ##CDB (ID, NAME) SELECT ID, NAME FROM #TEMP WHERE NAME<>''
DROP TABLE #TEMP
SET @V_COUNT=@V_COUNT+1
END
SELECT * FROM ##CDB
Thanks Shiven:) If Answer is Helpful, Please Vote -
How to read and write data in to a specified range of cells(it include multiple row & columns) in excel
CVI Comes with a sample project that explains how to read/write to a Excel file: choose "Explore examples..." in CVI welcome page and navigate to <cviSampleDir>\activex\excel folder where you can load excel2000dem.prj.
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
Reg : Concatenation of a column value with multiple rows... URGENT
Hello,
Could any of u help me in concatenating a column value with
multiple rows ???
For ex : I've the following data from emp table :
DEPTNO ENAME
10 KING'S
30 BLAKE
10 CLARK
10 TOM JONES
30 ALLEN
30 JAMES
20 SMITH
20 SCOTT
20 MILLER
10 MILLER
20 rajeev
I want the following output :
deptno Concat_value
10 KING'S,CLARK,TOM JONES,MILLER
20 Rajeev,MILLER,SMITH,SCOTT
30 BLAKE,ALLEN,JAMES
Thanks in Advance,
SriniHello Naveen,
Thanks for ur answer. But I need a single SQL query for getting
what I want. I know the solution in PL/SQL.
Please try it in a single SQL....
Thanks again,
Srini -
How do i delete multiple rows in JTable
hello
how i delete multiple rows in JTable
when i selected multiple rows from the jtable and delete its give the error ArrayIndexOutOfBoundException
e.g.
int rows[]=jtable.getSelectedRows();
for(int i=0;i<rows.length;i++)
DefaultTableModel model=(DefaultTableModel)jtable.getModel();
model.removeRow(rows);
like this
please help me
merajYou are trying to remove the rows an equal times to the amount of rows selected.
You should remove one row at a time:
model.removeRow(rows);
Change your code into this.
for(int i=0;i<rows.length;i++)
DefaultTableModel model=(DefaultTableModel)jtable.getModel();
model.removeRow(rows[i]); -
Please - immediate help needed parsing csv values into multiple rows
Hello, we have a very immediate need to be able to parse out a field of comma separated values into individual rows. The following is an example written in SQL Server syntax which does not work in Oracle.
The tricky part is that each ROUTES can be a different length, and each CSV can have a different number of routes in it.
Here is an example of the table ("Quotes") of CSV values I want to normalize:
TPNUMBER ROUTES
1001 1, 56W, 18
1002 2, 16, 186, 28
Here is an example of what I need it to look like:
TPNUMBER ROUTES
1001 1
1001 56W
1001 18
1002 2
1002 16
1002 186
1002 28
Here is the "Tally" table for the query below:
ID
1
2
3
4
5
6
7
And finally, here is the query which parses CSV values into multiple rows but which does not work in Oralce:
SELECT TPNUMBER,
NullIf(SubString(',' + ROUTES + ',' , ID , CharIndex(',' , ',' + ROUTES + ',' , ID) - ID) , '') AS ONEROUTE
FROM Tally, Quotes
WHERE ID <= Len(',' + ROUTES + ',') AND SubString(',' + Phrase + ',' , ID - 1, 1) = ','
AND CharIndex(',' , ',' + ROUTES + ',' , ID) - ID > 0
It may be necessary to use a cursor to loop through the CSV table and process each row (a loop within another loop...) but this is beyond my comprehesion of PL/SQL.
Many thanks in advance for your advice/help.
apkNot sure what you are trying to do with the last step, but this should work for the first part. I assume you would use sqlldr but I just did inserts instead. You might need more than 5 "routes" in the csv. You could put some reasonable max on that number of columns:
SQL>create table t_csv
2 (TPNUMBER varchar2(20),
3 ROUTE_1 VARCHAR2(5),
4 ROUTE_2 VARCHAR2(5),
5 ROUTE_3 VARCHAR2(5),
6 ROUTE_4 VARCHAR2(5),
7 ROUTE_5 VARCHAR2(5),
8 ROUTE_6 VARCHAR2(5) );
Table created.
SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2) values( '1001 1', '56W', '18' );
1 row created.
SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2,ROUTE_3) values( '1002 2', '16', '186', '28');
1 row created.
SQL>create table t_quotes(
2 tpnumber NUMBER,
3 routes VARCHAR2(5));
Table created.
SQL>DECLARE
2 L_tpnumber NUMBER;
3 L_route VARCHAR2(5);
4 begin
5 for rec in (select * from t_csv) loop
6 L_tpnumber := SUBSTR(rec.tpnumber,1,INSTR(rec.tpnumber,' ')-1);
7 L_route := SUBSTR(rec.tpnumber,INSTR(rec.tpnumber,' ')+1);
8 insert into t_quotes values( L_tpnumber, l_route );
9 if rec.route_1 is not null then
10 insert into t_quotes values( L_tpnumber, rec.route_1 );
11 end if;
12 if rec.route_2 is not null then
13 insert into t_quotes values( L_tpnumber, rec.route_2 );
14 end if;
15 if rec.route_3 is not null then
16 insert into t_quotes values( L_tpnumber, rec.route_3 );
17 end if;
18 if rec.route_4 is not null then
19 insert into t_quotes values( L_tpnumber, rec.route_4 );
20 end if;
21 if rec.route_5 is not null then
22 insert into t_quotes values( L_tpnumber, rec.route_5 );
23 end if;
24 end loop;
25 end;
26 /
PL/SQL procedure successfully completed.
SQL> select tpnumber, routes from t_quotes;
TPNUMBER ROUTE
1001 1
1001 56W
1001 18
1002 2
1002 16
1002 186
1002 28
7 rows selected. -
Exaprom PDF: how may cells span multiple rows in the table body?
I'm using Exaprom PDF but I have a case I just can't get to work.
I would like to generate a table where a cell spans on an entire row in the table body, the table should result as:
|__|__|__|__|
|__|__|__|__|
|___________|
|__|__|__|__|
Dear Jean-Marc,
could you post an example how to span a cell on an entire row in the table body with the function "Append Customized Table.vi."
For the example, please use the 2009 version.
Thanks,
Asper
This post refers to the Exaprom PDF report generation toolkit:
https://decibel.ni.com/content/docs/DOC-10952
Solved!
Go to Solution.Maybe this.
Jean-Marc
LV2009 and LV2013
Free PDF Report with iTextSharp
Attachments:
Test Table Merge LV2009.vi 113 KB -
Populating Combo Box list value In Multiple Row
Hi,
i to have the same problem .
I have used add_list_element to populate the list value of the combo box in multiple row.
I am selecting the list value from the database where the combo box value will be different for each row. However, when i do this.
All the previous row combo box list value will follow the combo box value in the last row. How can i resolve this?
i tried with lov but hasnt had any sucesss.in case of LOV can we make the list to appear automatuically and select a value????i havent had much sucesss over it??
is thr any work around for this apart from lov?Hi,
which product or technology are you talking about ?
Frank -
Need to return a cell value in a row where a date was selected from a column
I'm looking for a formula for OS Numbers and can't seem to find it.
I use the MIN function to select the earliest date in a range of cells. The dates all flow down one column. I need to be able to have numbers return the contents of a cell in the same row that was selected as the earliest date.
For example:
ID
Exp. Date
3
4
LJ-1
May-2014
LJ-2
Jun-2014
LJ-3
Jul-2014
LJ-4
Aug-2014
LJ-5
Sep-2014
I need to search for the earliest date in the 'Exp. Date' column and once it finds it, return the value from the 'ID' column.
So, in this case, i would need a formula to find May-2014 and return LJ-1 to the cell.
Any help would be greatly appreciated.Hi 86,
Rearrange your table then add another table to find the result:
A2 in Table 1-1 will find the earliest date in Table 1 without having to sort Table 1.
A2 contains this formula
=MIN(Table 1::A)
B2 in Table 1-1 uses VLOOKUP to find which ID matches that MIN date.
The reason for rearranging your table (Table 1) is that VLOOKUP compares a search value to the values in the leftmost column of a specified collection.
(in this case, it looks in the leftmost column of the range Table1::A:B, then returns a match from column 2 of that range).
I forgot to include "Exact Match" in the VLOOKUP formula. Is that what you want, or "Close Match"?
Edit: I don't suppose that matters because MIN will always give an exact match. Duh!
Regards,
Ian. -
Select single column but multiple rows in JTable
Hi
I have a jTable and want to be able to select multiple rows but only in a single column.
I've set these properties which makes selection almost the way I would like it.
table1.setCellSelectionEnabled(true);
table1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);the only problem now is that the user can select multiple columns.
Is there a simple way to restrict selection to single column?
regards
abqtable.setCellSelectionEnabled(true);
table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
DefaultListSelectionModel model =
(DefaultListSelectionModel)table.getColumnModel().getSelectionModel();
model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); -
Passing values of multiple rows to OracleCallableStatement
Hi,
I have a table with multiselection and a submit button. I want to select multiple rows and pass the values of selected rows one by one to a OracleCallableStatement in AM.
I have below code in CO. RowSelection is a transient attribute of type string in ItemsNotReturnedVO. 'Checked Value' is Y
When I run the page, select rows, click on Update button, I get this error. "*Attribute set for RowSelection in view object ItemsNotReturnedVO1 failed*"
if ("WaiveItemBtn".equals(pageContext.getParameter(EVENT_PARAM))) {
OAViewObject itemVO = (OAViewObject)am.findViewObject("ItemsNotReturnedVO1");
OARow row = (OARow)itemVO.first();
for(int i=0;i<itemVO.getRowCount();i++)
String appStatus=itemVO.getCurrentRow().getAttribute("RowSelection").toString();
if(appStatus.equalsIgnoreCase("Y"))
String vHeaderID = pageContext.getParameter("vTraHeaderId");
pageContext.putTransactionValue("vTraHeaderId", vHeaderID);
String vTempID = pageContext.getParameter("vTraTempId");
pageContext.putTransactionValue("vTraTempId", vTempID);
Serializable[] params = { vHeaderID,vTempID };
am.invokeMethod("waiveItemRequest", params);
row = (OARow)itemVO.next();
Below code in AM
public void waiveItemRequest(String vHeaderID, String vTempID){
try{
OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getDBTransaction();
OracleCallableStatement oraclecallablestatement =
(OracleCallableStatement)oadbtransactionimpl.createCallableStatement(" { call xxitemreturn_pkg.waive_item(:1,:2) } ",1);
oraclecallablestatement.setInt(1, Integer.parseInt(vHeaderID));
oraclecallablestatement.setInt(2, Integer.parseInt(vTempID));
oraclecallablestatement.execute();
catch(Exception e){
e.printStackTrace();
Using 10g database, Jdeveloper 10.1.3.3.0Hi Nadir,
The error is coming because you transient attribute is not updateable.
To make it updateable,
1) Open your VO
2) Go to Attributes
3) Select your transient attribute and make UPDATEABLE = Always.
Let me know, if this helps or you need further assistance.
Thanks
Saurabh -
Delete Multiple Rows of JTable by selecting JCheckboxes
Hi,
I want delete rows of JTable that i select through JCheckbox on clicking on JButton. The code that i am using is deleting one row at a time. I want to delete multiple rows at a time on clicking on Button.
This is the code i m using
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableTest extends JFrame implements ActionListener
JButton btnAdd;
BorderLayout layout;
DefaultTableModel model;
JTable table;JButton btexcluir;
public static void main(String[] args)
TableTest app = new TableTest();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public TableTest()
super("Table Example");
btnAdd = new JButton("Add");
btnAdd.addActionListener(this);
model = new DefaultTableModel()
public Class getColumnClass(int col)
switch (col)
case 1 :
return Boolean.class;
default :
return Object.class;
table = new JTable(model);
table.setPreferredSize(new Dimension(250,200));
// Create a couple of columns
model.addColumn("Col1");
model.addColumn("Col2");
JCheckBox cbox = new JCheckBox();
// Append a row
JPanel painel = new JPanel();
model.addRow(new Object[] { "v1",new Boolean(false)});
model.addRow(new Object[] { "v3", new Boolean(false)});
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.createVerticalScrollBar();
btexcluir= new JButton("Excluir");
btexcluir.addActionListener(this);
painel.add(btexcluir);
painel.add(btnAdd);
getContentPane().add(scrollPane, BorderLayout.NORTH);
getContentPane().add(painel, BorderLayout.SOUTH);
setSize(600, 600);
setVisible(true);
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnAdd)
model.addRow(new Object[] { "Karl", new Boolean(false)});
if (e.getSource()==btexcluir){
for (int i=0; i <=model.getRowCount(); i++){
if (model.getValueAt(i,1)==Boolean.FALSE)
JOptionPane.showMessageDialog(null, "No lines to remove!!");
else if(model.getValueAt(i,1)==Boolean.TRUE)
model.removeRow(i);
}Please reply me with code help.
Thanks
NitinHi,
Thanks for ur support. My that problem is solved now. One more problem now . Initially i want that delete button disabled. When i select any checkbox that button should get enabled. how can i do that ?
Thanks
Nitin -
Selecting multiple rows in JTable
Hi
I wonder if it is possible to select multiple rows in a JTable. I have written the following:
table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);However, when I select a second row, my first selected row unselects. I have to shift-click manually to select both rows. Is there a way around this (ie. without the shift-click part)?Well I have done that without finding anything... can you provide a link?
Maybe you are looking for
-
How to get the real SQL statement from a preparedstatement?
Hi, I am trying to log the actual SQL sent to database by the preparedStatement. Since the original SQL I used to prepare the statement has a lot of "?" in it, after setting all the parameters in the preparedStatement, I want to get the final SQL sta
-
Standard Valuation method in 8.8
Hi Experts, In the Itme Master Data the Item Cost is greyed out with the Standard Valuation method as soon as transactions is done. Is there any way I can change this standard Cost after transactions is posted? Thanks, Marli
-
Placing .indd file in another .indd causes errors
Hello, I am working with CS6 on a Windows 7 machine and I frequently place .indd files into other indd. files. Quite often indesign crashes when I have both of those indesign files opened. Just as I make changes in one of them and save it, indesign s
-
Our company have just upgraded to iOS 6 and the majority of the users are now receiving the following error 'Cannot Get Mail – Server error. Contact your server administrator' when accessing ms exchange this never happened on iOS 5 can anyone help
-
Large images may appear as black blocks. I've used 9GAG as an example because it happens quite often on 9GAG (so it was easy to find an example), but it happens on some other websites too. The images are displayed correctly in other browsers.