Creating a JTable with resizeable columns and Horizontal Scrollbar
Hi,
I would like to create a JTable with about 24 columns in it. The problem is, my ViewPort in my JScrollPane is about 3-400pixels wide, and the JTable tries to cram itself into the ViewPort. This makes the columns too tiny to read. I'd like it to do something a little more sensible, like use the PreferredSize of the columns. Can anyone point me in the right direction to keep JTable from creating scrunched up little columns, so that it creates columns that are at least partially readable? Thanks.
BTW, I suppose I could set NO_AUTO_RESIZE but I would rather not do that. I like being able to resize columns. Basically what I want to do is control the JTable's width and not worry about the ViewPort's width.
This made it impossible to resize columns. Works fine for me:
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableHorizontal extends JFrame
public TableHorizontal()
JTable table = new JTable(5, 10);
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane );
table.getColumnModel().getColumn(0).setPreferredWidth(10);
table.getColumnModel().getColumn(1).setPreferredWidth(20);
table.getColumnModel().getColumn(2).setPreferredWidth(30);
table.getColumnModel().getColumn(3).setPreferredWidth(40);
table.getColumnModel().getColumn(4).setPreferredWidth(50);
public static void main(String[] args)
TableHorizontal frame = new TableHorizontal();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
Similar Messages
-
How to create a table with editable column values.
Hi everyone,
I think this is very simple but i'm not able to find how to do this. This is my requirement. I need to create a table with n columns and 1 row initially. user should be able to enter data into this table and click of a button should insert data into the data base table. Also there should be a button at the bottom of the table to add 1 row to the table.
I know how to do the insert to database, but can anyone please let me know how to create a table that allows user to enter data and how to create a add 1 row button?
Thanks in Advance!Raghu,
Go through the ToolBox tutorial Create Page & Advanced table section of OAF Guide.
Step 1 - You require to create EO & a VO based on this EO. This EO will be of DataBase table where you want to insert the data.
Step 2 - Create a Advanced table region. (Refer this Adavanced table section for more on this)
Step 3 - Attach this VO in the BC4J component of Adavanced Table region.
Regards,
Gyan -
Dynamic gallery with 3 columns and 5 rows with paging
guyz, i am new to spry and i need your help. i want to create
a dynamic gallery with data source as xml. i want to create a
gallery with 3 columns and 5 rows.Basically a wallpaper page where
there would be 15 wallpapers in a page with a link of downloading
wallpapers with resolution 800x600,1024x768 and 1280x1024.
for example if there are 63 wallpapers for a section , then
there would be 5 pages with 5th page having only 3 wallpapers.
everytime a wallpaper is added to xml, it automatically adds
it up in html...
plz help....i really want to create this asap and i cant find
any help...thanks a ton for your response.... Meanwhile i figured out
the solution myself using photogallery tutorial where div fixes the
width and the next repeated element get shifted to another
line.....
now i am struck with another problem.
i need to give substring to a particular data on xml.
for example i have the following xml
<movies>
<data>
Important Note: These online forums are for user-to-user
discussions of Adobe products, and are not an official customer
support channel for Adobe. If you require direct assistance, or
prefer to contact Adobe support staff directly, please contact
Adobe support.
</data>
</movies>
i want to display only first 50 characters of data tag.....
whats the code/syntax to do so..... -
JTable with custom column model and table model not showing table header
Hello,
I am creating a JTable with a custom table model and a custom column model. However the table header is not being displayed (yes, it is in a JScrollPane). I've shrunk the problem down into a single compileable example:
Thanks for your help.
import javax.swing.*;
import javax.swing.table.*;
public class Test1 extends JFrame
public static void main(String args[])
JTable table;
TableColumnModel colModel=createTestColumnModel();
TestTableModel tableModel=new TestTableModel();
Test1 frame=new Test1();
table=new JTable(tableModel, colModel);
frame.getContentPane().add(new JScrollPane(table));
frame.setSize(200,200);
frame.setVisible(true);
private static DefaultTableColumnModel createTestColumnModel()
DefaultTableColumnModel columnModel=new DefaultTableColumnModel();
columnModel.addColumn(new TableColumn(0));
return columnModel;
static class TestTableModel extends AbstractTableModel
public int getColumnCount()
return 1;
public Class<?> getColumnClass(int columnIndex)
return String.class;
public String getColumnName(int column)
return "col";
public int getRowCount()
return 1;
public Object getValueAt(int row, int col)
return "test";
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
}Edited by: 802416 on 14-Oct-2010 04:29
addedKleopatra wrote:
jduprez wrote:
See http://download.oracle.com/javase/6/docs/api/javax/swing/table/TableColumn.html#setHeaderValue(java.lang.Object)
When the TableColumn is created, the default headerValue is null
So, the header ends up rendered as an empty label (probably of size 0 if the JTable computes its header size based on the renderer's preferred size).nitpicking (can't resist - the alternative is a cleanup round in some not so nice code I produced recently <g>):
- it's not the JTable's business to compute its headers size (and it doesn't, the header's the culprit.) *> - the header should never come up with a zero (or near-to) height: even if there is no title shown, it's still needed as grab to resize/move the columns. So I would consider this sizing behaviour a bug.*
- furthermore, the "really zero" height is a longstanding issue with MetalBorder.TableHeaderBorder (other LAFs size with the top/bottom of their default header cell border) which extends AbstractBorder incorrectly. That's easy to do because AbstractBorder itself is badly implemented
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6459419
Thanks for the opportunity to have some fun :-)
JeanetteNo problem, thanks for the insight :) -
How to create a datatable with row headers and column headers
Hi,
I am trying to create a two dimensional datatable which has both column headers and row headers. using <h:datatable> i could create a datatable with only column headers.
Thanks in advanceAre you saying that you want a column with only th's? You could also just apply some CSS on that specific column that its rows look like headers.
-
How to create 2D array with 3 rows and unlimit column?
how to create 2D array with 3 rows and unlimit column?
Here are images of what I described in my previous post
Message Edited by JoeLabView on 11-14-2007 07:56 AM
Attachments:
2D-array_code.PNG 7 KB
2D-array_values.PNG 13 KB -
How do I create a jtable with horizontalScroll bar,plz help me!
I created a jtable component,Because my table's columns has 50 items,I must need a horizontalScroll Bar.
but I find the horizontalScroll don't display,when I add record to the jtable,the verticalScroll Bar is showed.How do I create a jtable with horizontalScroll bar,can u help me!
thank you in advance!Hi,
This piece of code will help :
//Get the Component Adapter for taking action against resizing of
//of Panel
ComponentListenerAdapter componentAdapter =
new ComponentListenerAdapter()
//Get the scrollbar or remove the scrollbar upon resizing
protected void resizingAction()
Container tableParent = table.getParent();
if (tableParent instanceof JViewport)
//Check if the width of the Table Parent Container
//is less than the Preferred Size of the Table
if (tableParent.getSize().getWidth() <
table.getPreferredSize().getWidth())
//Yes it is
//Remove the Auton Resize Function and get the
//Scrollbar
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF );
else
//No it is not
//Get the Auto Resize functionality back in place
table.setAutoResizeMode(
JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
//Add the component Adapter to the Table Header
table.getTableHeader().addComponentListener(componentAdapter);
private abstract class ComponentListenerAdapter
implements ComponentListener
* The <code>componentHidden<code> method has no implementation
* @param event The Event occured whenever the Component is Hidden
public void componentHidden(ComponentEvent event)
//No Implementaion - Intentially Left Blank
* The <code>componentShown</code> method has no implementation
* @param event The Event occured whenever the Component is Shown
public void componentShown(ComponentEvent event)
//No Implementaion - Intentially Left Blank
* The <code>componentMoved</code> method has no implementation
* @param event The Event occured whenever the Component is Moved
public void componentMoved(ComponentEvent event)
//No Implementaion - Intentially Left Blank
* The <code>componentResized</code> method is invoked whenever the
* component is resized. The resizing action will set the columns and
* scrollbar to act properly
* @param event The Event occured whenever the Component is Resized
public void componentResized(ComponentEvent event)
resizingAction();
* Subclasses of this override this method to determine what is to be
* done once the Component has been Resized
protected abstract void resizingAction();
Hope this will solve all your JTable horizontal resizing problems
--j -
How do I create a JTable with some empty cells in it?
I have a three column JTable. The first column is a String showing description. The second column contains numbers (double) and the third column also contains numbers. In some cases not all cells in a row should contain data. So for instance, I could have row one showing only description (a String in the first column), and then row two showing description (a String in the first column) and a number (a double in the second column) in columns one and two respectively. My problem is that, the data gets copied from the cells with data to the cells which are supposed to be empty. So, how do I create a JTable with some empty cells in it.
I have tried empty strings for those values, but it did not work. My table puts objects in an arraylist called reconciliation. The arraylist takes different objects with the same super class. The code below explains. Are you suggesting I pass null to my constructor?
JTable table = new JTable(new ReconTableModel());The method below is from the table model
protected List<Reconciliation> reconciliation = new ArrayList<Reconciliation>();
protected void fillModel(){
reconciliation.add(new CashBook("Cash Book Report"," "," "));
reconciliation.add(new CheckingBankAccount("Checking Bank Account"," "," "));
reconciliation.add(new BankBalance("Bank Balance As Per Bank Statement",500," "));
reconciliation.add(new PaymentVouchers("Payment Voucher Receipt",300," "));
reconciliation.add(new DepositVoucher("Deposit Voucher Receipt",1000," "));
reconciliation.add(new ReconciledBalance("Reconcilied Bank Balance",1200," "));
reconciliation.add(new BalanceAt("Bank Balance At",800," "));
reconciliation.add(new Difference("Difference",400," "));
Collections.sort( reconciliation, new Comparator<Reconciliation>(){
public int compare( Reconciliation a, Reconciliation b) {
return a.getTransactionName().compareTo( b.getTransactionName());
} -
HOW TO CREATE A TABLE WITH 800 COLUMNS?
I have to create a table with 800 columns.I know the create statement to create a table but it will take more time.
So tell me the other method.If you really think that you have to store 800 values for a given entity, it would be a wise idea if you store you information in columnar fashion. Make a main table and a attribute table, keep the primary identifier in the main table and store other attributes in the attribute table where you can keep the primary key of the first table as foreign key (not necessary) to maintain the relationship.
eg.
emp_id
emp_name
dob
city
state
country
pincode
1
Mr X
01/01/1990
ABC
ZXC
MMM
12345
Can be stored as
Main Table
emp_id
emp_name
1
Mr X
Attribute Table
attr_id
emp_id
attr_nam
attr_value
1
1
dob
01/01/1990
2
1
city
ABC
3
1
state
ZXC
4
1
country
MMM
5
1
pincode
12345
Creating table with large number of columns is bad design as suggested by other Gurus.
Thanks -
Problem creating a table with a subquery and a dblink
Hello!!
I have a little problem. When I create a table with a subquery and a dblink, for example:
CREATE TABLE EXAMPLE2 AS SELECT * FROM EXAMPLE1@DBLINK
the table definition is changed. Fields with a type of CHAR or VARCHAR2 are created with a size three times bigger than the original table in the remote database. Field of type DATE and NUMBER are not changed. For example if the original table, in the database 1, has a field of type CHAR(1) it is create in the local database with a type of CHAR(3), and a VARCHAR2(5) field is created with VARCHAR2(15).
Database 1 has a WE8DEC character set.
Database 2 has a AL32UTF8 character set.
Could it be related to the difference in character sets?
What can I do to make Oracle use the same table definition when creating a table in this way?
Thanks!!That is related to character sets, and probably necessary if you want all the data in the remote table to be able to fit in the new table.
When you declare a column VARCHAR2(5), by default, you're allocating 5 bytes of storage. In a single-byte character set, which I believe WE8DEC is, that also happens to equate to 5 characters. In a multi-byte character set like AL32UTF8, though, 1 character may require up to 3 bytes of storage, so you'd need to allocate 15 bytes to store that data. That's what's going on here.
You could still store all the data if you create the table locally by explicitly requesting 5 characters of storage by declaring the column VARCHAR2(5 CHAR). You could also set the NLS_LENGTH_SEMANTICS parameter to CHAR rather than BYTE before creating the table, but I believe that both of these will only apply when you're explicitly defining columns as part of your CREATE TABLE. I don't believe either will apply to CTAS statements.
Justin -
How to create a form with two column headings
I have a business request to create a data form to handle multi year data by month. This will require creating a form with two column headings - with the first row be Year and second row be month, and data entry will begin in the third row and down.
I can do multiple row headings in the layout design, but somehow can not get it to work for multiple column headings.
Thanks in advanceIf you're in the "Layout" tab, simply pull the "Years" dimension and the "Period" dimension into the Column section. Planning can be a little picky about where you "drop" the dimension as you're dragging and dropping it. Drop it in the cell directly under the letter name of the column. Other than that, there's not much to it.
Hopefully this helped,
- Jake -
How To Create Table View With Same Column name But Different Table?
Hi All,
I have the problem to create a tableview with same column name but in different table.
The Table that i have:-
Table - PAC051MPROFORMA
Column - mrn,visitid
Table - PAC051TPROFORMA
Column - mrn,visitid
Table - PAC052MTRANSBILL
Column - mrn,visitid
Then i want to create a table view to view that table. This is my SQL
CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
where
*(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
and
*(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
That SQL Return this error = ORA-00957: duplicate column name
Then I modify that SQL to
CREATE VIEW pacviewproforma (mrn,visitid)
As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
where
*(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
and
*(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
This time this error return = ORA-01730: invalid number of column names specified
What should i do?
Thanks...Hi,
SQL> CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
2 As Select
3 PAC051MPROFORMA.mrn,
4 PAC051MPROFORMA.visitid,
5 PAC051TPROFORMA.mrn,
6 PAC051TPROFORMA.visitid,
7 PAC052MTRANSBILL.mrn,
8 PAC052MTRANSBILL.visitid
9 from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
10 where
11 (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
12 and
13 (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
ERROR at line 1:
ORA-00957: duplicate column namePlease give different names to each column.
Something like this..
SQL> CREATE OR REPLACE VIEW pacviewproforma (MPROFORMA_mrn,MPROFORMA_visitid,TPROFORMA_mrn,TPROFORMA
_visitid,MTRANSBILL_mrn,MTRANSBILL_visitid)
2 As Select
3 PAC051MPROFORMA.mrn,
4 PAC051MPROFORMA.visitid,
5 PAC051TPROFORMA.mrn,
6 PAC051TPROFORMA.visitid,
7 PAC052MTRANSBILL.mrn,
8 PAC052MTRANSBILL.visitid
9 from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
10 where
11 (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
12 and
13 (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
View created.
SQL> DESC pacviewproforma;
Name Null? Type
MPROFORMA_MRN NUMBER
MPROFORMA_VISITID NUMBER
TPROFORMA_MRN NUMBER
TPROFORMA_VISITID NUMBER
MTRANSBILL_MRN NUMBER
MTRANSBILL_VISITID NUMBER
ORA-01730: invalid number of column names specifiedThe list of column nmae you specified during the CREATE VIEW should match with the SELECT list of the view.
Twinkle -
Has anyone been able to create a HtmlDataTable with dynamic col and rows?
Has anyone been able to create a HtmlDataTable with dynamic col and rows?
If so please explain. I am successfully able to dynamically add columns using the getChildren method of the htmldatatable object
BUT for each new column created no data is displayed.
I am only able to display data for columns originally created when i clicked and dragged the dataTable icon from the pallette in netbeans visual web kit.
Any help on this is greatly appreciated. I have been searching the web and these forums for around 8 hours and no one seems to have a working example of this. Lots of similar posts asking how to do it though :(
Thanks in advance.This might be useful: http://balusc.xs4all.nl/srv/dev-jep-dat.html
-
How to create a contract with one supplier and two dealers?
Hi Gurus,
I have a contract with a supplier (eg. Apple), but the products and services are supplied by two dealers.
The supplier is the manufacturer and with whom the negotiation of prices is made.
The dealers are those who make the delivery of the products and services and who the payment is done.
How can I create a contract with these characteristics in SRM 7.0?
I don't want to create two contracts with same products and services for two suppliers (Dealer_1 and Dealer_2).
How can this be handled through business partner type "Vendor"?
In "Partner" section in "Header" --> "Basic data", I can only add 1 vendor.
The system is:
Component software: SRM_SERVER
Release: 700
Level: 0008
Support package: SAPKIBKV08
Thanks in advance and best regards,
Alonso ValenzuelaHi Wadim,
I have a similar requirement to create order lines in an existing contract with reference using BAPI_CUSTOMERCONTRACT_CHANGE. The order lines get created in the contract. However, the condition types from the order line which i'm referencing are not getting referenced and are not getting added in the Contract's line after referencing.
Did you come across any such issue ? If yes , could you suggest the solution ?
Regards,
Venkat. -
Dear sirs,
Could you please help me on my problem with my apple ID
I create new account with security questions, and when I try to purchase paid application,it ask me for answers the questions but it's not working,
My account have 50$ and still didn't buy anythingYou need to ask Apple to reset your security questions; ways of contacting them include clicking here and picking a method for your country, phoning AppleCare and asking for the Account Security team, and filling out and submitting this form.
(100546)
Maybe you are looking for
-
Am i missing the most basic setting for RMAN in RAC?
DB version: 10.2.0.4 We've set up a 2 node RAC environment. Everything is working fine (failover,...etc).Each node can 'view' other node's archive log destination from OS level. ie. When you type df -hboth nodes can see each other's location of archi
-
Is it possible to have a superdrive on a ibook G4 12" ?
I'm definetely new to apple but also vary bad with computers...! I want to buy an ibook G4 12" but only if I could have a superdrive on it. I understand that I can't buy it with a superdrive, but is it possible to have someone to put it later? ibook
-
" "
-
Hi Friends In my scenario, I am trying to do an Idoc to RFC and response of RFC is being sent to Email , we are using Request Response bean and ResponseOnewayBean, but problem is there are lots of other scenarios with same sender system and sender in
-
Is it possile to disable info update by default in ME21N? Any help would be appreciated