Setting custom font to each column of a JTable

Hi
Does anyone can provide me a source code of a JTable where each column has a different font? As I saw, I can change font of all columns by calling myTable().getTableHeader().setFont(), but it's not what I want.
regards.

Make Your own cellRenderer by extending the TableCellRenderer class.
getTableCellRendererComponent is the method you need.
public java.awt.Component getTableCellRendererComponent(javax.swing.JTable jTable, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
if(row==-1){//heading row
jLabel l=new JLabel();
l.setText((String)value);
switch(col){
case(0)//add a case for every column
l.setFont(myFont);
break;
default:
break;
return l;
else{
return super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,col);
then just set the renderer:
table.getTableHeader().setDefaultRenderer(new myRenderer());

Similar Messages

  • How to set custom font family in qml label in black berry 10 os

    how to set custom font family in label text  qml in black berry 10 OS

    AFAIK, this is not the correct way to set the image location.
    We call the working directory as context, so inside the context root along with WEB-INF, maintain a folder with name img and put all the images in that directory.
    You can use either .\<image_folder> or the optimum way would be (if you are using JSPs) to use getContext() method and traverse accordingly.
    FYI,,, using getContext() will give you context root directory, from there it is as simple as accessing any other folder.
    Hope this answers your question.
    Cheers,
    Jeets.

  • How to get each column position in JTable?

    I want some buttons appear at the top of each column. For example,
      Button1    Button2  Button3
    | column1 | column2 | column3 |
    |--------------------------------------------|
    ...But button1,2 and 3 should be at the top of the column1, 2 and 3. So the problem is that how can I get each column's position.

    gajesh wrote:
    To get column index using column heading name, use following:-
    table.getColumnModel().getColumnIndex(columnName)You should use your own TableCellRenderer for header column:
    MyButtonHeaderRenderer extends JButton implements TableCellRenderer {
    <class definition>
    then you can set user-defined renderer to header column:-
    getColumnModel().getColumn(colIndex).setHeaderRenderer(new MyButtonHeaderRenderer());
    But the button is outside of the JTable. It is on the top of the Table. So I don't think implementing HeaderRender works here.
    I need to know each column's position (x,y) and place the button on the top of the columns.

  • How to set different font for a particular row in jtables?

    How to set different font size and font type for a particular row in jtable?

    More than enough sample code here:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]
    db

  • Setting the Size of a Column in a JTable

    Hi there,
    does anybody knows a way how to set the size of a specified column in a JTable without changinge the size of the other columns?
    thx anyway
    Errraddicator

    You've got to change the JTable's column resizing policy to prevent the other columns resizing:
    JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)Otherwise all the columns will be adjusted to fit into the width of the table - changing one column would have to result in at least one other column changing!
    Hope this helps.

  • How to set a JRadioButton as a column in a JTable

    Hello Friends,
    I need a help in JTable.
    I want to have a Radio button as a column of a JTable.(The Other Columns should be Strings).
    The heading of the Column which has the RadioButton is "Select" which means that I can select only one radiobutton at a time.
    Could you please give me a solution on this.
    I would appreciate if u give me the code for this, as it is very urgent.
    Thanks in Advance,
    Regards,
    Vijayakannan

    Hi,
    use a TableCellRenderer and CellEditor as described in http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Propably you need to track the selected button yourself, e.g. by using an int value representing the row selected.

  • Set custom font size for one column

    hey guys! I am trying to decrease the font-size for one column based on an lov and used
    style="font-size:8pt"It does not work though! Do you have a hint?
    brgds,
    seb

    Hello Seb,
    >> Might it be important whether the column is of type "...based on lov"?
    If by "...based on lov" you mean “Display as Text (based on LOV, does not save state)” the answer is yes. This type of column is not treated as an updatable column (the implementation is by using a regular <td> tag and not the <input> tag) so the Apex engine ignores the Element Attributes field.
    As far as I can tell, this column can only be styled in the query itself (and you need to implement the LOV yourself).
    Another option is to use a select list and disabled it, but the column will appear in gray, and with small font size it doesn’t look that good.
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Forthcoming book about APEX: Oracle Application Express 3.2 – The Essentials and More

  • Creating a custom editor for each cell in a Jtable

    camirk, i know its swing ;) so
    http://forum.java.sun.com/thread.jspa?threadID=652383
    im just posting this link here for people who dont read the swing forum but are looking for the same solution
    hope it helps someone :)

    Two days after you posting you original question: http://forum.java.sun.com/thread.jspa?threadID=651625&messageID=3831712
    you find the answer on your own. Yes, the general Java forum sure is helpfull.
    If the question was posted in the Swing forum you would have had the answer in a couple of hours:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581

  • Custom bleeds for each page?

    i changed the size of a page using the page tool to be smaller than other pages in the same document. but the bleed is huge?
    i set the bleed to be .5 all around and it looks good on all the pages except this one
    can i set custom bleeds for each page?

    Eric Greenfield wrote:
    i set the bleed to be .5 all around and it looks good on all the pages except this one
    can i set custom bleeds for each page?
    First, .5 whats? .5 inches, for example would be huge for normal work, .5 pica or cm a bit large, and .5 mm or pt exceptionally small. and essentially useless.
    And bleed guides are set as a document level attribute, so one size fits all pages. That actually is a good thing, by the way. Bleed is there to provide a buffer against misalignment in cutting. The size you need is based on the sheet-to-sheet registration capabilities of the printing equipment and the accuracy of the cutter and skill of the operator, and it doesn't change with the page size.

  • How to set custom widths for a particular report column?

    how could I set a custom width for a particular report column? Is there a way to do it using css?
    Thank you.

    Hi Leland,
    I have tested this here: [http://apex.oracle.com/pls/otn/f?p=267:18]
    All I have done is add the following into the report's Region Header:
    &lt;style type="text/css"&gt;
    #apexir_EMPNO {width:200px}
    #apexir_ENAME {width:200px}
    #apexir_DEPTNO {width:200px}
    .apexir_WORKSHEET_DATA TR TD {height:100px;}
    &lt;/style&gt;The headers have all be set to be left-aligned. Each column should be 200px wide (even though I'm setting the width on the headers, it will be applied to the entire column unless a cell's contents is wider, in which case the column is made wider). The final entry above adjusts the height of all TDs within the IR table.
    Andy

  • Set-up custom font, font size, and color for writing new and reply e-mails in Thunderbird

    I know that I can select the font, size, and color for writing each new and reply e-mails in Thunderbird, but I don't want to have to do this each time. I want to set-up the default font, size, and color for all new and reply e-mails. It already comes up with a default one, but I want to change it, but can't figure out how to do this. I'm sure it is quite simple, but I don't know how to do this. Thank you in advance for help.

    Tools > Options > Display > Formatting tab
    Default font: select font
    Select size : eg; 14
    Click on 'Advanced' button and set all the sizes to 14
    Select : 'allow messages to use other fonts'
    click on OK
    Click on 'Composition'
    Under the 'General' tab
    Suggest you set HTML font to 'Variable width' and Size : 'Medium'
    Select the 'Text colour' you would like to compose email using
    Select the 'Background colour' you would like to use when composing emails.
    click on OK to save all changes.
    This will set the display email list to the selected font.
    It will allow received emails to use the font the sender used.
    When you compose an email it will also use the same font settings.
    The message 'Display' settings in the above section also apply to messages that you compose. The settings are not sent, so they do not affect how your messages appear to recipients.
    The settings in the ''Composition' section can affect how messages are sent. If you make unusual choices, then people who receive messages from you might find them difficult or impossible to read. Hence, why I suggest you leave it as 'Variable width' and allow the 'Display' settings to set the default used for composing emails.
    More info:
    * http://kb.mozillazine.org/Font_settings_in_Thunderbird

  • Font.properties to set custom in-house fonts

    Hi all,
    Currently attempting to get Forms Server to display a custom fonts called TH Sans Serif which is MS Sans Serif modified for our special needs. We need to show a whole array of fonts which caters for Rumanian, Hungarian, Polish, Slovak, Western European fonts amongst others. Problem is that the font.properties file (loaded with Jinitiator to be found under %Jinitiator_Home%\lib) maps 4 fonts (Monospaced, SansSerif, Serif, Dialog) that are used in the registry.dat file. Apparently reading from newsgroups it is possible to set one of these four mappings to your own custom font. Haven't unfortunately found a success case yet. Can anyone help.
    Thanks in advance.

    Please use the Forms forum for best response.
    Ashesh Parekh
    Oracle9iAS Product Management

  • Setting font of a column headers

    Hi!
    How can I set a font (size,color, etc.) of column headers in tabular form?
    Tom

    Hi Tom,
    you must edit the font of the column header in the CSS of your theme!
    Look at the HTML Code in the Template of your tabular form, which CSS Class du you have to change!
    Regards,
    Tim

  • Can't set custom column widths in JTable

    I'm trying to set custom columns widths. They are set as I wish but then they are reset to default values (all columns have the same size). This is caused by method JFrame.setVisible(true) which invokes JTree.setWidthsFromPreferredWidths(). It can be investigated from following stack trace printed when a column being resized (see below).
    How to prevent this auto width sizing?
    P.S. can't override JTable.setWidthsFromPreferredWidths(); seems it's private
    table = new JTable(model) {
         public void columnMarginChanged(ChangeEvent event) {
              new Exception("stack trace").printStackTrace();
              super.columnMarginChanged(event);
    // setting here custom columns widths via table column model ...java.lang.Exception: stack trace
         at mtu.gui.TrackList$1.columnMarginChanged(TrackList.java:30)
         at javax.swing.table.DefaultTableColumnModel.fireColumnMarginChanged(DefaultTableColumnModel.java:615)
         at javax.swing.table.DefaultTableColumnModel.propertyChange(DefaultTableColumnModel.java:679)
         at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:264)
         at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:232)
         at javax.swing.table.TableColumn.firePropertyChange(TableColumn.java:249)
         at javax.swing.table.TableColumn.firePropertyChange(TableColumn.java:255)
         at javax.swing.table.TableColumn.setWidth(TableColumn.java:482)
         at javax.swing.JTable$2.setSizeAt(JTable.java:2242)
         at javax.swing.JTable$5.setSizeAt(JTable.java:2336)
         at javax.swing.JTable.adjustSizes(JTable.java:2372)
         at javax.swing.JTable.adjustSizes(JTable.java:2340)
         at javax.swing.JTable.setWidthsFromPreferredWidths(JTable.java:2250) <======
         at javax.swing.JTable.doLayout(JTable.java:2165)
         at java.awt.Container.validateTree(Container.java:1089)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validateTree(Container.java:1096)
         at java.awt.Container.validate(Container.java:1064)
         at java.awt.Window.show(Window.java:455)
         at java.awt.Component.show(Component.java:1134)
         at java.awt.Component.setVisible(Component.java:1089) <=====
         at mtu.gui.Test.test_03(Test.java:56)
         at mtu.gui.Test.main(Test.java:29)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.intellij.rt.execution.application.AppMain.main(Unknown Source)

    When I create the table I have code like this:TableColumn col = getColumnModel().getColumn(2);
    col.setMinWidth(width + 4);
    col.setMaxWidth((int)(width * 1.2));Works just fine for me. The setWidthsFromPreferredWidths() method will use these limits as far as I can see.
    PC&#178;

  • How to change font size, maximum column size in the result screen ?

    hi All
    That's great when using SQL Dev.
    But I also have a trouble that how to change font size, maximum column size in the result screen ?
    My users think that font in result screen is shown very small, and whenever the data in each colum is long then it's not shown full data in column, they must double click for extend the size. Have the option to default the max size for showing full data in each column ? I try but still not to do that .
    Appreciate for anyone to help us.
    Thanks all.
    Sigmasvn

    You can't change the font for the results screen yet, however you will be able to select an auto-fit option for selected columns, so if some columns have slitghtly wider text you'll be able to set the column widths to handle these wider columns.
    Also, there s the option of switching the layout of a record in the grid.
    Sue

Maybe you are looking for