How can I use a column header to select columns in a JTable?
Hello,
I've been working for ages on this, but I still can't come up with a suitable solution. What I want to be able to do is select a column header from a JTable, which in turn would select the corresponding column in my JTable. I cant seem to do this with a mouse listener, and I can't see how to toggle the buttons of the header either.
Any help would be gratefully appreciated.
Mike
I have both row and columns selected depending on what you do in the JTable. Here's my code:
where you init your JTable add:
addressTable = new JTable(addressTableModel, addressTableColumnModel);
JTableHeader th = addressTable.getTableHeader();
th.addMouseListener(new tableHeaderMouseAdapter(addressTable));
addressTable.getSelectionModel().addListSelectionListener(new selectionListener(addressTable));
addressTable.setColumnSelectionAllowed(true);
tableHeaderMouseAdapter looks like this (it should look familiar):
private class tableMouseAdapter extends MouseAdapter
private JTable tableView;
public tableMouseAdapter(JTable newTableView)
tableView = newTableView;
public void mouseClicked(MouseEvent e)
int selectedRow = tableView.getSelectedRow();
if ((e.getClickCount() == 1) && (selectedRow != -1))
tableView.clearSelection();
tableView.setRowSelectionInterval(selectedRow, selectedRow);
tableView.setColumnSelectionInterval(0, tableView.getColumnModel().getColumnCount() - 1);
selectionListener looks like this:
private class selectionListener implements ListSelectionListener
private JTable tableView;
private boolean changingSelection;
public selectionListener(JTable newTableView)
tableView = newTableView;
changingSelection = false;
public void valueChanged(ListSelectionEvent e)
if ((!changingSelection) && (tableView.getSelectedColumnCount() < tableView.getColumnCount()) && (tableView.getSelectedRowCount() < tableView.getRowCount()))
changingSelection = true;
int selectedRow = tableView.getSelectedRow();
if (selectedRow >= 0)
tableView.clearSelection();
tableView.setRowSelectionInterval(selectedRow, selectedRow);
tableView.setColumnSelectionInterval(0, tableView.getColumnModel().getColumnCount() - 1);
changingSelection = false;
I'm sure there is a better way to do this, but it's the first thing I could get to work.
disclamer:
Use this code at your own risk. I make no claims about this code whatsoever.
Similar Messages
-
How can i use the highlight row to select the row on a report
The row is highlighted as I move the mouse how can I select this row without having to make a column a text link.
thanks in advanceHi
Try this out.
Create or alter a report template. In the 'Before Each Row' section paste:
<tr onMouseOver="cOn(this);" onMouseOut="cOut(this);">
In the 'After Each Row' section paste:
</tr>
In the report page definition click on the page attributes and navigate to the HTML Header section. Paste the following script into this section:
</script>
<script language="JavaScript1.2">
function cOn(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#cccccc";
function cOut(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#ffffff";
</script>
In the report region navigate to the 'Layout and Pagination' section and select the report template you altered above.
Now the report row will get highlighted when you mouse over. If you want to change colors, edit the color attributes in the javascript.
Regards
Kiran Akkiraju -
How do I use a Presentation Variable to select Column/Views of a Request
I have multiple requests that all have view / column selectors in them (all the same columns)
What I would like is to create a dashboard prompt that the user can select from that will influence these multiple requests on the same dashboard page.
Thanks for any help.User,
As I read that example it has
Year - Year Ago - Dollars
The dropdown selector they've created looks very useful in that it allows them to filter those three columns with 50+ filters.
What I'm trying to do is something like this (for multiple different requests of course)
Year - Year Ago - Dolloars - Column 1
or
Year - Year Ago - Dolloars - Column 2
or
Year - Year Ago - Dollars - Column 3 -
How can i use param in my select query ( see code)
Hi ,
I need to use the param instead of hardcoding the value in the select query , when i did that it is working .
I think the limit of args is only till the end of main and my select query is in a method called Load() .
How can i use the param in my select query .
public static void main(String[] args){
name = args[0];
class= args[1];
new Load();
}//end of main
public Load()
try {
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,"username","pw");
statement = connection.createStatement();
//First Query : pin and ticket number
ResultSet resultSet = statement.executeQuery("SELECT pin , ticketnumber from airport ,year where "+ "year.year_name= Here i need to use the param (instead of hardcoding) and year.class_year= Here too i need to use param");
}// end of method Load()Edited by: 1sai on Sep 24, 2008 7:34 AM
Edited by: 1sai on Sep 24, 2008 7:35 AMMight I suggest you change the structure of your program to the following:
public class Load {
private Connection conn;
private PreparedStatement statement;
public Load(String sql) {
init(sql);
protected void init(String sql) throws Exception {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DATABASE_URL, "username", "pw");
statement = conn.prepareStatement(sql);
public ResultSet execute(String p1, String p2) throws Exception {
statement.setString(1, p1);
statement.setString(2, p2);
return statement.executeQuery();
public void close() throws Exception {
if (statement != null)
statement.close();
statement = null;
if (conn != null)
conn.close();
conn = null;
public static void main(String[] args) throws Exception {
String sql = args[0];
String param1 = args[1];
String param2 = args[2];
Load load = new Load(sql);
ResultSet rs = load.execute(param1, param2);
while (rs.next())
System.out.println(rs.get(0));
rs.close();
load.close();
}This allows you to use the same "Load" object for multiple queries with different parameters.
I do not recommend you actually use the code above in any sort of production application. You should really take a look at Spring Framework along with an ORM tool like Hibernate or Ibatis to simplify your DAO layer.
Hope this helps,
David -
Hi Experts,
How can i get a file header using this method cl_gui_frontend_services=>gui_download
Thanks
BasuHi,
You can use the FM - GUI_DOWNLOAD to specify the headers. It can be done in the following manner -
TYPES: BEGIN OF ty_head, "Structure for header
h(10) TYPE c,
END OF ty_head.
DATA: it_head TYPE TABLE OF ty_head WITH HEADER LINE.
"Adding header details
it_head-h = 'Field1'.
APPEND it_head.
it_head-h = 'Field2'.
APPEND it_head.
it_head-h = 'Field3'.
APPEND it_head.
it_head-h = 'Field4'.
APPEND it_head.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = p_file
filetype = 'ASC'
write_field_separator = 'X'
header = '00' "<= note this
TABLES
data_tab = it_tab
fieldnames = it_head[] "<= Pass your header table here
EXCEPTIONS
OTHERS = 1.
Hope this helps.
Regards,
Himanshu -
How can I use Automator to extract specific Data from a text file?
I have several hundred text files that contain a bunch of information. I only need six values from each file and ideally I need them as columns in an excel file.
How can I use Automator to extract specific Data from the text files and either create a new text file or excel file with the info? I have looked all over but can't find a solution. If anyone could please help I would be eternally grateful!!! If there is another, better solution than automator, please let me know!
Example of File Contents:
Link Time =
DD/MMM/YYYY
Random
Text
161 179
bytes of CODE memory (+ 68 range fill )
16 789
bytes of DATA memory (+ 59 absolute )
1 875
bytes of XDATA memory (+ 1 855 absolute )
90 783
bytes of FARCODE memory
What I would like to have as a final file:
EXCEL COLUMN1
Column 2
Column3
Column4
Column5
Column6
MM/DD/YYYY
filename1
161179
16789
1875
90783
MM/DD/YYYY
filename2
xxxxxx
xxxxx
xxxx
xxxxx
MM/DD/YYYY
filename3
xxxxxx
xxxxx
xxxx
xxxxx
Is this possible? I can't imagine having to go through each and every file one by one. Please help!!!Hello
You may try the following AppleScript script. It will ask you to choose a root folder where to start searching for *.map files and then create a CSV file named "out.csv" on desktop which you may import to Excel.
set f to (choose folder with prompt "Choose the root folder to start searching")'s POSIX path
if f ends with "/" then set f to f's text 1 thru -2
do shell script "/usr/bin/perl -CSDA -w <<'EOF' - " & f's quoted form & " > ~/Desktop/out.csv
use strict;
use open IN => ':crlf';
chdir $ARGV[0] or die qq($!);
local $/ = qq(\\0);
my @ff = map {chomp; $_} qx(find . -type f -iname '*.map' -print0);
local $/ = qq(\\n);
# CSV spec
# - record separator is CRLF
# - field separator is comma
# - every field is quoted
# - text encoding is UTF-8
local $\\ = qq(\\015\\012); # CRLF
local $, = qq(,); # COMMA
# print column header row
my @dd = ('column 1', 'column 2', 'column 3', 'column 4', 'column 5', 'column 6');
print map { s/\"/\"\"/og; qq(\").$_.qq(\"); } @dd;
# print data row per each file
while (@ff) {
my $f = shift @ff; # file path
if ( ! open(IN, '<', $f) ) {
warn qq(Failed to open $f: $!);
next;
$f =~ s%^.*/%%og; # file name
@dd = ('', $f, '', '', '', '');
while (<IN>) {
chomp;
$dd[0] = \"$2/$1/$3\" if m%Link Time\\s+=\\s+([0-9]{2})/([0-9]{2})/([0-9]{4})%o;
($dd[2] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of CODE\\s/o;
($dd[3] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of DATA\\s/o;
($dd[4] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of XDATA\\s/o;
($dd[5] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of FARCODE\\s/o;
last unless grep { /^$/ } @dd;
close IN;
print map { s/\"/\"\"/og; qq(\").$_.qq(\"); } @dd;
EOF
Hope this may help,
H -
How can I use table headers only without using rows.
how can I use table headers only, without using rows and without leaving the space.
If anyone could say me how to paste the pic in this questions, I would have shown it.
The flow of view is in this way
{Table header(table on top of table)
column header1___|| column header2__ || column header3__ ||}
<b>Here is the blank space I am getting, How to avoid this space?this space is of one table row height</b>
{Contents column1 || Contents column2 || Contents column3 || (This is of other table below the uper table)}
I am using scroll for the content part of table only.
So I am using two tables.
I am using NW04.I did the possibles you explained, but couldn't get rid off the space.
Any other solutions?
I am keeping the header static and the content columns scrollable.
I have used two tables one to display header above and the other to display only the contents.
I have put the contents table in scroll container.
And the header table in transperent container.
Thanks and Regards,
Hanif Kukkalli -
How can i use one SQL statement to solve problem?
How can i use one SQL statement to solve the question below?
For a Table named A, there is a column named F(char type).
Now select all the records where F like '%00' and update their F value to '%01'
Just one SQL statement.Do not use PL/SQL block.
How to do that?
Thanks.What is the data volume for this table?
Do you expect lots of rows to have '%00' as their value?
Following two statements come to mind. Other experts would be able to provide better alternatives:
If you have index on SUBSTR(f, 2):
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) || '01'
WHERE substr(f,
-2) = '00';If most of the rows have pattern '%00':
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) ||
DECODE(SUBSTR(f,
-2),
'00',
'01',
SUBSTR(f,
-2)); -
How can I use my time capsule with windows7
How can I use my time capsule with windows7?
This is asked regularly.
https://discussions.apple.com/message/10978060#10978060
Look at the more like this. On the right column next to the post.
Load airport utility for windows.. which will also load bonjour for windows.
In windows explorer type \\TCname or \\TCipaddress (replacing with the actual values.. names with spaces will give you trouble so change all names in the TC to SMB compatible or actual ip address). -
How can I use comma in the return values of a static list of values
Hi all,
I want to create a select list (static LOV) like the following:
Display Value / Return Value
both are "Y" / 'YY'
one is "Y" / 'YN','NY'
I write the List of values definition is like this:
STATIC:both are "Y"; 'YY',one is "Y";'YN', 'NY'
However, it is explain by htmldb like this:
Display Value / Return Value
both are "Y" / 'YY'
one is "Y" / 'YN'
/ 'NY'
I tried using "\" before the ",", or using single or double quote, but all these do not work:(
How can I use a comma in the return values?
Thanks very much!"Better still, why not process the code of both Y with 2Y and one is Y with 1Y? "
Could you please explain in detail? thanks! I am quite new to htmldb
In fact I have a table which has too columns "a1" and "a2", both the values of these two columns are "Y" or "N". AndI want to choose the records that both a1 and a2 are "Y", or just one of a1, a2 is "Y".
So I write the report sql like this:
"select * from t1 where a1 || a2 in(:MYSELECTLIST) "
Thus, I need to use "," in the LOV, since expression list in IN(,,,) using ",".
Any other way to implement this? -
How can i use Button in BEx 7.0
Dear Folks,
Could you help me please ..
In BI 7.0, for BEx analyzer i see we can use button, combo box, analysis grid.
If i have a requirement like this:
1. I have sales report, where it has information about sales person.
2. And i want to filter that report with the sales person that i choose from combo box.
For that requirement, i tried to :
1. I Create a query to Sales info-provider for displaying sales.
2. I Create a query to either to MD Sales person / Sales info-provider in order to get Sales persons data.
3. I assign point no 1 to Analysis Grid.
4. I assign point no 2 to Combo box.
My questions are:
a. Is my techniques correct ??
b. How can i use button to execute filter into the corresponding report ???
c. Is there any tutorial regarding this ?? Could you share it to me please ..
Really need your guidances..
regards,
Niel..Hi Niel,
You can use the method you specified.
In Bex Analyzer you have design mode where you can have the following items Button, Analysis Grid and Combo box.
To work with the button you need to use the Command Wizard which consists of pre-defined functions, out of those select the one which suits your requirement and supply the parameters. As it is done thorugh a Wizard it would be easy to do.
Also,
The Button Name displays the name of the button, which is generated automatically and is unique. This name is used on the BEx Analyzer Design Toolbar menu to refer to a particular instance of the button.
· Range u2013 Manipulate coordinates for a cell or cells in this field to move or resize the button.
· Button Text - The text (caption) you want to display on the button. You can use this to describe the command the button executes.
· Command Range (optional) - Specify a three-column range of cells in the worksheet that contains command parameters. In these cells, you provide the same parameters (Name, Index, and Value) as in the Static Parameters, but in the worksheet these can be variable, changing during
navigation based on query results or on a value you manually specify.
Button in Bex analyzer
Regards,
Neelesh Jain. -
User Variable Options: How can I use them in a Business Rule?
How can I use a "User Variable" set in File / Preferences in a Business Rule? It doesn't seem to appear as an Essbase Substitution Variable or as a Global Variable of Business Rules. The only way I know how to use it is to place the dimension on the POV or Page dimension of a data form, then use a Global Variable in a run time prompt to pick the member and run a BR against it, or some function of it.
What do I do if I want to have that dimension in Columns or Rows? How can I set a BR to directly reference the member chosen under User Variable Options?
JThanks Alp, but I can't seem to reproduce what you are writing below. I want to refer my Business Rule to address the value set in File / Preferences / User Variable Options; no matter what members I show elsewhere in the data form.
My other workaround is through a run time prompt and hope the user selects the appropriate user variable at the very bottom of the selection list in order to calculate the appropriate list of members.
J -
How can I use an iPad with two itunes accounts?
How can I use an iPad with two itunes accounts?
Hi there
My partner has a works iPad, which has her works Apps on (ones that are specifically made by her company and are NOT available in the App store).
What I want to be able to do is to ALSO have my itunes account on there so that I can put all the apps I have purchased previously from my iPhone on it.
This is so I can put on VLC player (thats already in my itunes account) so I can add videos to the iPad.
How do I do this please?
I tried it before by connecting it to my mac, but it wiped everything off the iPad completely and also deleted the data settings for using 3G.
So I want to avoid this happening again the future as it had to be sent back to her head office to be sorted again.
Any advise please?
ThanksYou can't. The iPad is desgined to be a 'one user' device and only really works with one apple ID at a time.
The only way would be if she, at work and with her work apple id, downloaded your apps (repurchasing them of course).
It's not meant to be a multiple user/multiple ID device. -
How can i use multiple row subquery in update statement
Hai All
I using group function in my update statement.. and i need to update more rows so i need to use multiple row
subquery pls tell me how to use multiple row subquery in update statement
For example
while i am using this like this i got an error
update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
Pls tell me how to use with example
Thanks & regards
Srikkanth.MHai Man
Thanks for ur response Let me clear what i need
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
And my coding is
declare
emp_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor P1 is
Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
From temp_att
group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
ORDER BY enpno,pdate,ptime;
begin
for r2 in p1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r2.inout ='O' then
update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
end if;
end loop;
exception
when no_data_found then
if r2.inout ='I' then
insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
end if;
end;
end loop;
commit;
end;
Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
and how can i use it in the update statement
Thanks In Advance
Srikkanth.M -
How can I use multiple row insert or update into DB in JSP?
Hi all,
pls help for my question.
"How can I use multiple rows insert or update into DB in JSP?"
I mean I will insert or update the multiple records like grid component. All the data I enter will go into the DB.
With thanks,That isn't true. Different SQL databases have
different capabilities and use different syntax, That's true - every database has its own quirks and extensions. No disagreement there. But they all follow ANSI SQL for CRUD operations. Since the OP said they wanted to do INSERTs and UPDATEs in batches, I assumed that ANSI SQL was sufficient.
I'd argue that it's best to use ANSI SQL as much as possible, especially if you want your JDBC code to be portable between databases.
and there are also a lot of different ways of talking to
SQL databases that are possible in JSP, from using
plain old java.sql.* in scriptlets to using the
jstlsql taglib. I've done maintenance on both, and
they are as different as night and day.Right, because you don't maintain JSP and Java classes the same way. No news there. Both java.sql and JSTL sql taglib are both based on SQL and JDBC. Same difference, except that one uses tags and the other doesn't. Both are Java JDBC code in the end.
Well, sure. As long as you only want to update rows
with the same value in column 2. I had the impression
he wanted to update a whole table. If he only meant
update all rows with the same value in a given column
with the same value, that's trivial. All updates do
that. But as far as I know there's know way to update
more than one row where the values are different.I used this as an example to demonstrate that it's possible to UPDATE more than one row at a time. If I have 1,000 rows, and each one is a separate UPDATE statement that's unique from all the others, I guess I'd have to write 1,000 UPDATE statements. It's possible to have them all either succeed or fail as a single unit of work. I'm pointing out transaction, because they weren't coming up in the discussion.
Unless you're using MySQL, for instance. I only have
experience with MySQL and M$ SQL Server, so I don't
know what PostgreSQL, Oracle, Sybase, DB2 and all the
rest are capable of, but I know for sure that MySQL
can insert multiple rows while SQL Server can't (or at
least I've never seen the syntax for doing it if it
does).Right, but this syntax seems to be specific to MySQL The moment you use it, you're locked into MySQL. There are other ways to accomplish the same thing with ANSI SQL.
Don't assume that all SQL databases are the same.
They're not, and it can really screw you up badly if
you assume you can deploy a project you've developed
with one database in an environment where you have to
use a different one. Even different versions of the
same database can have huge differences. I recommend
you get a copy of the O'Reilly book, SQL in a
Nutshell. It covers the most common DBMSes and does a
good job of pointing out the differences.Yes, I understand that.
It's funny that you're telling me not to assume that all SQL databases are the same. You're the one who's proposing that the OP use a MySQL-specific extension.
I haven't looked at the MySQL docs to find out how the syntax you're suggesting works. What if one value set INSERT succeeds and the next one fails? Does MySQL roll back the successful INSERT? Is the unit of work under the JDBC driver's control with autoCommit?
The OP is free to follow your suggestion. I'm pointing out that there are transactions for units of work and ANSI SQL ways to accomplish the same thing.
Maybe you are looking for
-
What is an easy web-page creation program for use with MacBook Pro?
Can anyone suggest an easy web-page creation program for use with MacBook Pro? I have used FrontPage with my PC, but am changing to a MacBook Pro.
-
How can i change the length of a narration ?
how can i change the length of a narration ?
-
I'm using Logic 9 with a Macbook Pro. On one project I'm getting a message 'not enough processor power' and the computer stops playing I've tried freezing all tracks but this has no effect. I've also bounced all soft synth tracks to audio, but to no
-
Next album track not playing automatically
When I listen to my music on I Tunes the next album track does not come on automatically. Can anyone advise me what I need to do please - presumably soemthing to do with the settings ?
-
APSDaemon.exe process causes iTunes to fail on Windows 7
I am using iTunes with Windows 7 64bit. A couple of days ago my pc downloaded the latest iCloud update in the Apple Updater. Since then when I start iTunes it will lock up when opened requiring a task manager shutdown to exit. I traced the problem to