f



How to center or right justify JTable column data?

Probably a FAQ... but here goes...

How do I force all JTable column entries to be right aligned or center
aligned?  It appears the default is left aligned.

Thanks,

Jack


0
Jack
2/3/2004 3:15:50 AM
comp.lang.java.gui 8286 articles. 0 followers. Post Follow

1 Replies
3691 Views

Similar Articles

[PageSpeed] 41

"Jack" <Jackverbosity@verboseerrors.net> wrote in message
news:GnETb.26985$%72.24588@twister.nyroc.rr.com...
> Probably a FAQ... but here goes...
>
> How do I force all JTable column entries to be right aligned or center
> aligned?  It appears the default is left aligned.
>
> Thanks,
>
> Jack
>
>

Jack,

I beleive you will need to implement your own table model. The Java tutorial
at http://java.sun.com/docs/books/tutorial/uiswing/components/table.html is
what I read through to get around a similar problem. I created my own table
model and used a custom renderer.

class MyJLabelRenderer extends JLabel implements TableCellRenderer {

    // constructor
    MyJLabelRenderer() {
        this.setHorizontalAlignment(CENTER);
    }

    // returns component to use as renderer
    public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int col) {
        // could have some other logic in here...
        return this;
    }
}


0
Flo
2/3/2004 3:53:13 AM
Reply:

Similar Artilces:

CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean
Hello, I have discovered a hidden error. My project was working for awhile, but then I started to get the below error. My error comes from the fact that I'm using a checkbox in a jtable, and I'm using the below "getColumnClass". Thank you, compile: run: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:5412) at javax.swing.JTable.prepareRenderer(JTable.java:5735) at javax.swing.plaf.basic.BasicTableU...

How to right justify a column
Hello group, I am feeling pretty good about this program. I am just learning and am trying to get the basics down. I would like to ask if someone could tell me how to right justify the BALANCE column in my program's output. =============== Here is my code: =============== #include <stdio.h> int main (void) { int i; int accountNumber[10]; char lastName[10][30]; float accountBalance[10]; printf("Enter account number, last name, and balance.\n"); printf("Enter -999 to end input.\n"); for (i = 0; i < 10; i++) { printf(&...

Right Justify A Column
Good Morning, Within a shell script I have du -ak /auto/dc3-cad/cad/dc3/boards/balestra16/ | sed -n ./\.brd$/p. redirected to file appears as 39632 /auto/dc3-cad/cad/dc3/boards/bremgarten_xl_pbfree/BREM-10_PBFREE_110719_REFRESH.brd 141440 /auto/dc3-cad/cad/dc3/boards/nurburgringXL-pbfree/SAVE/NURB-XL_PBFREE_110718_REFRESH_JS.brd 141088 /auto/dc3-cad/cad/dc3/boards/nurburgringXL-pbfree/NURB-XL_PBFREE_110721_REFRESH_JS_162.brd 89144 /auto/dc3-cad/cad/dc3/boards/supervisor_everland/rev01/pcb/history/ucs_b2000_sup-28-10189-01_02.brd 39188 /auto/dc3-cad/cad/dc3/boards/supervisor_everla...

java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace: java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException at COM.ibm.db2.jdbc.app.DB2Driver.SQLAllocEnv(Native Method) at COM.ibm.db2.jdbc.app.DB2Driver.<init>(DB2Driver.java:245) at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(DB2Driver.java:130) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Cla...

Using "Justify" in ODS RTF Output (rather than left/right/center justify)
I was posed the question off list about how to write data to an ODS RTF destination "justified". Justify is the option you get in word that spreads text across the full width of a line and proportionally spaces it out, as oppoed to left/right and center justify. There doesn't seem to be an ODS style attribute for it, at least not documented in V8.2. But you can do it quite easily by embedding a raw RTF code (\qj) as follows (I've done all of the justification codes for comparison). One question arises .. what would you use the "distribution" justification for? dat...

Re: Using "Justify" in ODS RTF Output (rather thanleft/right/center justify)
"Nigel Pain" <Nigel.Pain@SCOTLAND.GSI.GOV.UK> wrote: >From trying this out, Distributed appears to be like Justified but >rather than just spacing out words to get neat margins, it spaces out >characters. Can't imagine how you'd use it but who knows what strange >things people might want?! Incidentally, there doesn't seem to be any >way of getting Word 2002 to do this even though it recognises it when >reading the RTF file. "Distributed" is what professional typesetters usually do - there are additional tiny spaces between letters inst...

Re: Using "Justify" in ODS RTF Output (rather than left/right/center justify)
******************************************************************************************************************************************************* This email and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. ******************************************************************************************************************************************************* From trying this out, Distributed appears to be like Justified but rather than just spacing out words to get neat margins, it spaces out characters. Can't im...

java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460)
Hi All I am having the torque3.1.jar and postgresql-7.4. I have compiled the new jdbc driver called as postgresql.jar and have placed it in the lib directory from where the ant scripts catch the jars. Whenever i try to access through torque gestList = BaseGestlistPeer.doSelect(new Criteria()); this error arises java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460) at org.postgresql.jdbc2.ResultSet.toTimestamp(ResultSet.java:1653) at org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java...

Capturing Java GUI data
Hi, I'm looking for any way to capture data generated by a GUI tool made in Java. It's possible ? Thanks On 02/14/2012 10:01 PM, contracer wrote: > Hi, > I'm looking for any way to capture data generated by a GUI tool made > in Java. > It's possible ? > Thanks It is possible. The way begins here: <http://www.oracle.com/technetwork/java/javase/documentation/index.html> Am 15.02.2012 04:01, schrieb contracer: > Hi, > I'm looking for any way to capture data generated by a GUI tool made > in Java. > It's possible ? > Thanks Hi contrac...

java.lang.Set with elements of type java.lang.Set
Roughly I do something along the lines of: Set set = new HashSet(); Set elem = new HashSet(); set.add(elem); // now we change the elem and add it again to the set elem.add(some object here); set.add(elem); I found out the hard way that 'set' may now contain 'elem' either once or twice, the reason being that 'elem.add()' changes the hashCode of elem such that it is not noticed that it is in 'set' already on the 2nd 'set.add()'. Question: What I would actually want is an IdentityHashSet() set = new IdentityHashSet() but this does not...

SN#20602 Data Center Pulse: A Community for Data Center Professionals
SYSTEM NEWS FOR SUN USERS Vol 127 Issue 3 2008-09-15 Article 20602 from section "Features" A Chance to Share on What's Really Happening in the Data Center Data Center Pulse, an exclusive group of global datacenter owners, operators and users, was just inaugurated by Dean Nelson, senior director at Sun in his regular blog, Geekism. The declared goal of Data Center Pulse is to track the pulse of datacenter trends through discussions and debate. Details at http://sun.systemnews.com/g?A=20602 Have a custom version of 'System Ne...

to use import java.lang.* or import java.lang.Math or none at all?
Hi guys, i knew that by default all java.lang classes will be imported by the compiler during compilation. but, to make it easier for the computer, should i specify which class i really will be using? does this action will boost the performance during compilation and runtime or not a matter at all? the answer to this post will definitely affect my programming style in the future when i'm considering "to import or not to import"... hmm,,, thanks in advance. JPractitioner wrote: > i knew that by default all java.lang classes will be imported by the > compiler during com...

Java Data Aware GUI framework?
Hi Anyway knows of a good (production) free java data aware GUI framework? (im a bit mixed up i have noticed there is DBSwing that seems to me to be the best its costly i think (not sure) and I would rather working with eclipse... anyone has good experience with such? (my searches over the net just confused me since I have noticed a few, but couldnt tell if one is used and if there is a leading framework...) Hi, I made a framework called JForm what does what you want, it is often referenced as an alternative for DbSwing. It's production stable but not for free... You can find more info...

Column data display (Am I on the right track?)
I have some data I wanted to display in tables. I think I started off doing this the hard way. I made a lot of labels on another form, and figured I would just modify those labels for whatever data needs to be changed, and assing that data to those labels. I noticed some sort of built in table would make things easier. Then I thought of Excel tables, and I then added the Sheet object into my forum. I am thinking it may be best to get used to this as it (in theory) should make things easier, you agree? My only problem is modifying the cells, but it's just my newbieness. I just...

Web resources about - How to center or right justify JTable column data? - comp.lang.java.gui

Can Religion Justify Bullying Children? by Sean Faircloth - YouTube
The book "Attack of the Theocrats: How the Religious Right Harms Us All & What We Can Do About It" is available in audiobook, electronic, and ...

How Malcolm Turnbull plans to justify the ABC's $250 million budget cut
ABC staff will be forced to walk to a pigeonhole to collect their mail at the new streamlined public broadcaster.

'Difficult to justify' … water charges to rise on lost revenue
'Difficult to justify' &#8230; water charges to rise on lost revenue

Can we justify paying people smugglers to go back to Indonesia?
May a government or its representatives collude with iniquity for the sake of some greater good? In general, the answer is 'yes' &ndash; but ...

Bending the law – does the end justify the means?
It is one of the great moral dilemmas. Can we do something that on the surface appears to be wrong if it prevents a greater evil?

Social media sledging didn't justify Dugan's abuse
Josh Dugan had 2 million reasons to walk away from a social media fight, but couldn't resist getting in the ring.

Burka bandits justify a burka ban
The burka is no longer simply the symbol of female repression and Islamic culture, it is now emerging as the preferred disguise of bandits and ...

Michael Brown family statement: Robbery allegations don't justify 'execution-style murder'
The family of Michael Brown released a statement following allegations that their son was involved in a convenience store robbery the day he ...

Ensuring vets don't have to repeatedly justify wounds easier said than done
Making sure wounded ex-soldiers most notably amputees don't have to repeatedly verify their injuries to retain their benefits is proving much ...

Japan tries to justify Abe's shrine visit
People's Daily Online Japan tries to justify Abe's shrine visit People's Daily Online Publishing articles in influential newspapers is an ...

Resources last updated: 2/4/2016 2:18:30 PM