How to resize the columns of a table?
Hi there!
I want to resize the column of a JTable(constructed via AbstractTableModel) to
fit the exact width of the word in the header?
Can anyone tell me how to do this thing?
Regards,
import java.awt.*;
import javax.swing.table.*;
public class ColumnResizeDemo extends javax.swing.JFrame {
public ColumnResizeDemo() {
initComponents();
TableColumn column = null;
for (int i = 0; i < jTable1.getColumnModel().getColumnCount(); i++) {
column = jTable1.getColumnModel().getColumn(i);
String hv = column.getHeaderValue().toString();
JTableHeader th = jTable1.getTableHeader();
FontMetrics fm = th.getFontMetrics(th.getFont());
column.setPreferredWidth(fm.stringWidth(hv)+5);
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Column Resize Demo");
jLabel1.setText("Sets column width to fit exactly the corresponding header value");
getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
new String [] {
"Title 1", "Title 0002", "Title 0000003", "Title 00000000000004"
jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
jScrollPane1.setViewportView(jTable1);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
pack();
public static void main(String args[]) {
new ColumnResizeDemo().setVisible(true);
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
}
Similar Messages
-
How to sum the column in a table seperated by sign.
How to sum the column in a table separate by sign.
For Example:
A B
10 MOHAN
-15 KUMAR
-25 MARCH
50 MAYSELECT SUM(CASE SIGN(A) WHEN 1 THEN A ELSE NULL END) SUM_POSTIIVE,
SUM(CASE SIGN(A) WHEN -1 THEN A ELSE NULL END) SUM_NEGATIIVE
FROM tbl
/SY. -
How to find the column name and table name with a value
Hi All
How to find the column name and table name with "Value".
For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
Any help is highly appricatable
Thanks & Regards
Srikkanth.M2 solutions by Michaels (the latter is 11g upwards only)...
michaels> var val varchar2(5)
michaels> exec :val := 'as'
PL/SQL procedure successfully completed.
michaels> select distinct substr (:val, 1, 11) "Searchword",
substr (table_name, 1, 14) "Table",
substr (t.column_value.getstringval (), 1, 50) "Column/Value"
from cols,
table
(xmlsequence
(dbms_xmlgen.getxmltype ('select ' || column_name
|| ' from ' || table_name
|| ' where upper('
|| column_name
|| ') like upper(''%' || :val
|| '%'')'
).extract ('ROWSET/ROW/*')
) t
-- where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
order by "Table"or
SQL> select table_name,
column_name,
:search_string search_string,
result
from cols,
xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
columns result varchar2(10) path '.'
where table_name in ('EMP', 'DEPT')
TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
DEPT DNAME ES RESEARCH
DEPT DNAME ES SALES
EMP ENAME ES JONES
EMP ENAME ES JAMES
EMP JOB ES SALESMAN
EMP JOB ES SALESMAN
EMP JOB ES SALESMAN
EMP JOB ES PRESIDENT
EMP JOB ES SALESMAN
9 rows selected. -
How to resize the column header according to row data
Hi,
How can i resize the column header according to row date .. means if data is small header should be small and vice versa ,...
Any help is appreciated .. Snippet will be more helpful .
Thanks,
ShekharOxley (binkley) blogged about this: http://binkley.blogspot.com/2006/01/getting-jtable-columns-widths-to-fit.html
Christian Ullenboom | tutego -
How I compare the columns of 2 tables
Hi, what's the query I use to compare all the columns of 2 tables, or how I use the result of COLUMN_NAME in the DBA_TAB_COLS?
Tnks for helping...
MnkI have this select:
SELECT D.COLUMN_NAME AS CFINAL
FROM DBA_TAB_COLS D,
(SELECT A.COLUMN_NAME AS C1
FROM DBA_TAB_COLS A
WHERE (A.OWNER LIKE '%TEL_USJ07%' AND
A.TABLE_NAME = 'BOLETOS')) F
WHERE D.COLUMN_NAME = F.C1
AND D.OWNER LIKE '%TEL_USJ07%'
This will return the column's name where tabel_name LIKE BOLETOS.
I want use this result in another select where the table have this columns and more, but I want to see all the results in the second table where the columns came from the first select.
For example: the first select bring to me the columns: cod_tipo_bol and cod_tipo_corte, I want to see in the second select only the results of this 2 columns.
THIS IS THE COLUMNS OF THE SECOND TABLE I WANT TO USE:
cod_tipo_bol
cod_frente_corte
num_carga
cod_caminhao
cod_motorista
lib_numero
cod_enc_frente
cod_div2
cod_div3
cod_div4
bol_data
cod_carregadora1
cod_oper_carreg1
cod_carregadora2
cod_oper_carreg2
cod_colhedora1
cod_oper_colhed1
cod_colhedora2
cod_oper_colhed2
cod_colhedora3
cod_oper_colhed3
cod_trat_reb
cod_oper_trat_reb
cod_trat_transb1
cod_oper_transb1
cod_trat_transb2
cod_oper_transb2
cod_trat_transb3
cod_oper_transb3
cod_julieta_sm_reboque
bol_status
-------- -
How to get the column name and table name with value
Hi All
I have one difficult requirement
I have some column values and they have given some alias column names but i need to find the correct column name and table name from the database.
For example value is "SRI" and i dont know the table and exact column name so is there any possibilities to find the column name and table name for the given value
Thanks & Regards
Srikkanth.MSearching all the database for a word...
Courtesy of michaels...
michaels> var val varchar2(5)
michaels> exec :val := 'as'
PL/SQL procedure successfully completed.
michaels> select distinct substr (:val, 1, 11) "Searchword",
substr (table_name, 1, 14) "Table",
substr (t.column_value.getstringval (), 1, 50) "Column/Value"
from cols,
table
(xmlsequence
(dbms_xmlgen.getxmltype ('select ' || column_name
|| ' from ' || table_name
|| ' where upper('
|| column_name
|| ') like upper(''%' || :val
|| '%'')'
).extract ('ROWSET/ROW/*')
) t
-- where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
order by "Table"or
11g upwards
SQL> select table_name,
column_name,
:search_string search_string,
result
from (select column_name,
table_name,
'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
from cols
where table_name in ('EMP', 'DEPT')),
xmltable (str columns result varchar2(10) path '.')
TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
DEPT DNAME es RESEARCH
EMP ENAME es JAMES
EMP JOB es SALESMAN
EMP JOB es SALESMAN
4 rows selected. -
How to resize the columns in the report
Hi
I want to resize the columns in my report to make them smaller so that they don't overlap, but after resizing the columns still overlap so that some columns headings are under the other ones.
ThanksYou can do it either by, going to the property palette of the column and then change the horizontal elasticity to 'Variable', this way it will shrink or enlarge the size automatically. Or, you can do in manually in the layout model, click the column then click the edge of the field and drag it to make it longer or shorter.
-Marilyn -
How to optimize the column width in Table Control
Hi all,
When I am displaying fields in Table Control, the columns are displayed in full length, and I am unable to see all the fields at once.
So as in grid , where we optimize the column width using layout, do we had any property for TC to do so.
thanks for your help.
Points would be awarded .
Regards,
Anil .Hi,
In Se51, you can do this one, ust open your table control and resize the TC, there is no direct option to do this for entire TC, you need to do this field by field, and arrage the TC to adjust in a Single screen. In the field parameters, you have the field lenghts, there you can minimize the length of a field
Regards
Sudheer -
How to unhide the column in Alv table
Hi Experts,
Initially i have created webdynpro Alv table with 8 columns ,later i have added one more attribute/column to the node to display extra column
but in the output ,alv table not displaying the 9th column,Instead the column is getting hidden which i came to know clicking on settings in alv table output.If i make changes in Alv table settings it getting displaying,can anyone tell me how to unhide this field.
Regards
SandeshHi Sandesh,
It is possible that the user you are loggin in with, might have a layout saved.
You can try logging in with different user and see if its still hidden.
The explicit code to hide and unhide a column :
lo_alv_column->set_visible( if_wdl_core=>visibility_none ).
may be you can use the above code and make column visibility true(cahnge parameter).
Regards,
Tashi -
How to fix the column length and table length?
Hi Experts/Gurus,
I want to fix the column lenght so that if data exceeds it should be in the same colum. But the size of the table should not get changed.. I used the width property of both table and column. But its not working..
Regards,
YugeshHi Yugesh,
For column wrapping you can use the SET_WRAPPING of cl_salv_wd_header and the data.....you have got cell editor for that column right...then using the cell edtior reference you can get the specific cell tyep(like cl_salv_wd_text_view type check this)
this is object reference and you can use the set_wrapping of this class. using this you can get the wrapping functionality for the data also....
DATA: lr_column TYPE REF TO cl_salv_wd_column,
lr_column_header type ref to cl_salv_wd_header,
lr_editor type ref to cl_salv_wd_uie,
lr_textview type ref to cl_salv_wd_uie_text_view.
wd_this->alv_value->if_salv_wd_table_settings~set_fixed_table_layout( ABAP_TRUE ).
lr_column = wd_this->alv_value->if_salv_wd_column_settings~get_column( 'EDITION' ).
lr_column->set_width( '55' ).
lr_column_header = lr_column->get_header( ).
lr_column_header->set_wrapping( abap_true).
lr_editor = lr_column->get_cell_editor( ).
lr_textview ?= lr_editor.
lr_textview->set_wrapping( abap_true ).
Now for the column and it's data the wrapping is set...
Regards,
Lekha.
Edited by: Lekha on Nov 16, 2009 2:12 PM -
How to resize the column of alv depending upon the textbox settings in i.e
Hi,
I am using ALV component in one of my WD applications. ALV has a column date. If i resize the textbox from the internet explorer setting ( page->textsize in i.e.7) to anything greater than medium, the content of the columns is hidden.
For example, if the date is displayed as 25/07/2010, after resizing it appears as 25/07...
i have tried using column property of the alv : set_width and set_resizable, but it doesnt give the desired output.
Please give ur suggestions.
Regards,
VarunaHi,
Would increasing the width of ALV itself help?
using IF_SALV_WD_TABLE_SETTINGS~SET_WIDTH().
Regards,
Aditya. -
How to get the column name and table name from xml file
I have one XML file, I generated xsd file from that xml file but the problem is i dont know table name and column name. So my question is how can I retrieve the data from that xml file?
Here's an example using binary XML storage (instead of Object-Relational storage as described in the article).
begin
dbms_xmlschema.registerSchema(
schemaURL => 'my_schema.xsd'
, schemaDoc => xmltype(bfilename('TEST_DIR','my_schema.xsd'), nls_charset_id('AL32UTF8'))
, local => true
, genTypes => false
, genTables => true
, enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_CONTENTS
, options => dbms_xmlschema.REGISTER_BINARYXML
end;
genTables => true : means that a default schema-based XMLType table will be created during registration.
enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_CONTENTS : indicates that a repository resource conforming to the schema will be automatically stored in the default table.
If the schema is not annotated, the name of the default table is system-generated but derived from the root element name :
SQL> select table_name
2 from user_xml_tables
3 where xmlschema = 'my_schema.xsd'
4 and element_name = 'employee';
TABLE_NAME
employee1121_TAB
(warning : the name is case-sensitive)
To annotate the schema and control the naming, modify the content to :
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb">
<xs:element name="employee" xdb:defaultTable="EMPLOYEE_XML">
<xs:complexType>
Next step : create a resource, or just directly insert an XML document into the table.
Example of creating a resource :
declare
res boolean;
doc xmltype := xmltype(
'<employee>
<details>
<emp_id>1</emp_id>
<emp_name>SMITH</emp_name>
<emp_age>40</emp_age>
<emp_dept>10</emp_dept>
</details>
</employee>'
begin
res := dbms_xdb.CreateResource(
abspath => '/public/test.xml'
, data => doc
, schemaurl => 'my_schema.xsd'
, elem => 'employee'
end;
The resource has to be schema-based so that the default storage mechanism is triggered.
It could also be achieved if the document possesses an xsi:noNamespaceSchemaLocation attribute :
SQL> declare
2
3 res boolean;
4 doc xmltype := xmltype(
5 '<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:noNamespaceSchemaLocation="my_schema.xsd">
7 <details>
8 <emp_id>1</emp_id>
9 <emp_name>SMITH</emp_name>
10 <emp_age>40</emp_age>
11 <emp_dept>10</emp_dept>
12 </details>
13 </employee>'
14 );
15
16 begin
17 res := dbms_xdb.CreateResource(
18 abspath => '/public/test.xml'
19 , data => doc
20 );
21 end;
22 /
PL/SQL procedure successfully completed
SQL> set long 5000
SQL> select * from "employee1121_TAB";
SYS_NC_ROWINFO$
<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceS
<details>
<emp_id>1</emp_id>
<emp_name>SMITH</emp_name>
<emp_age>40</emp_age>
<emp_dept>10</emp_dept>
</details>
</employee>
Then use XMLTABLE to shred the XML into relational format :
SQL> select x.*
2 from "employee1121_TAB" t
3 , xmltable('/employee/details'
4 passing t.object_value
5 columns emp_id integer path 'emp_id'
6 , emp_name varchar2(30) path 'emp_name'
7 ) x
8 ;
EMP_ID EMP_NAME
1 SMITH -
How do I resize the column in numbers for the iPad
Hi, I have numbers app in my iPad and I can't figure out how to resize the columns. There are no column headers when I create a new spreadsheet, and I can't click between the columns and even when I turn wrap text off it doesn't resize just overlay.
I hope there has to be a way that I just can't figure out as it seems like a very simple task that should be obvious.
KarenaTap on any cell in a table to bring up the table options. You'll see two bars above and to the left of the table. There is a dot in a circle on the top left, and two toggles to increase/decrease the number of rows or columns. To change the width of a column, tap in the bar above the table in the column which you want to resize, and that column will become highlighted. From here you can select multiple columns using the handles to resize multiple columns at once. In the bar at the top, there are two little dashes - drag this left and right to resize the column.
-
Reg:How to delete the column in table control also from database table.
Hi Experts,
Once again thank u all for giving the responses.
one more doubt is how to delete the columns of table control and also the record shold delete from ztable.
With Regards,
Saroja.P.Hi,
If you want to delete the rows in the table control and simultaneously delete it from the database table, then you can implement a 'DELETE' functionality specific to your table control. Have a MARK field (you will find that in the screen attributes of the table control -> give a name for the MARK field, you will find an additional MARK column at the beginning of your table control). You can check whatever rows you want to delete from the table control, call the delete module.
"This portion of code inside the LOOP...ENDLOOP.
IF sy-ucomm eq 'F_DELETE'.
gt_itab2-check = mark. " Store the MARK field status into your internal table's correspoding field 'check'
MODIFY gt_itab INDEX tabcontrol-current_line.
ENDIF.
iF sy-ucomm eq 'DELETE1'.
DELETE gt_itab WHERE check eq 'X'. "Your internal table does not have rows that you want to delete
ENDIF.
Now you can modify your database table using the MODIFY statement.
MODIFY ZDB FROM TABLE gt_itab. -
How we can replace the column in Core Table plz see this msg
Hi,
How we can replace the column in Core Table plz see this msg
Req:
when i push the Insert button the data inserted into the Table
like
Cols Values
FOCD CUFZ14
PRDCD FU6
Month 082008
AgencyCD AG02
PLAN 123
This is FO_Plan Table....
Requirement:
i need at table show to replace the Prd_CD to Prd_Desc while inserting the above Row....
There is no Prd_Desc in FO Plan Table....
Prd_desc comes from Product Table.
did u get my point...
how to solve.
Thanks
Ram
Edited by: Ram Vungarala on Sep 24, 2008 9:09 AM
Edited by: Ram Vungarala on Sep 24, 2008 9:15 AMHi,
I'm not sure if I understood what are you trying to do. But you can modify your table in a backing bean code. JSF page code for a table:
<af:table id="product_search_results_tbl" binding="#{backingBean.boundTable}" ... />
And a backing bean code:
import oracle.adf.view.faces.component.core.data.CoreTable;
public class YourBackingBean {
private CoreTable boundTable;
public void setBoundTable(CoreTable boundTable) {
this.boundTable = boundTable;
public CoreTable getBoundTable() {
return boundTable;
public String insertButtonAction() {
// Bind your button action to this method and modify here your bound table
return null;
{code}
Look for column modification methods in a CoreTable class documentation.
Marius
Maybe you are looking for
-
Reversing and Resetting the Excise Invoice No. in Sales
Hi Gurus, Kindly give me solution to reverse and reset the excise invoice after billing. The client has created manual invoice and manual excise nos. have been given for few documents and invoice has been despatched to the party. When they are upda
-
After Effects CS6 Crashes Upon Opening
Here is the problem: I have After Effects CS6, and it and other creative suite programs have been working just fine, until recently. This just started a few days ago after every time I open After Effects to start a project it immediately closes and I
-
I want to reduce (or remove) camera shakes in a video with Premiere Pro CS5. Is there an build-in plugin I can use, or do I have to download / buy one? Thanks.
-
Hi can somebody help me to know the what are explain plan and execution plan?what is the differnce between them? thankz in advance
-
First PKGBUILD: blobby2-svn
Hi, this is my first PKGBUILD for the svn-version of Blobby Volley 2. Please test it before I'll put it into AUR: pkgname=blobby2-svn pkgver=375 pkgrel=1 pkgdesc="Blobby Volley 2 - SVN version" url="http://blobby.redio.de/content/de/index.php" licens