J Table - Single Cell Alignment

Hello everyone,
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
public class RowColorTest
    private JTable table;
    public static void main(String[] args)
        new RowColorTest();
    public RowColorTest()
        javax.swing.SwingUtilities.invokeLater(new Runnable()
            public void run()
                createGUI();
    public void createGUI()
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        String[] columnNames = new String[4];
        columnNames[0] = "Name";
        columnNames[1] = "Age";
        columnNames[2] = "Value";
        columnNames[3] = "Extra";
        Object[][] data = new Object[20][4];
        Random r = new Random();
        for(int a=0; a < 4; a++)
            for(int i=0; i < 20; i++)
                if(i == 0 || i == 5 || i == 10 || i == 15)
                    data[i][a] = 23;
                else
                    data[i][a] = r.nextInt(50);
        DefaultTableModel model = new DefaultTableModel(data, columnNames);
        table = new JTable(model)
            public boolean isCellEditable(int rowIndex, int vColIndex)
                return false;
            public Class getColumnClass(int column)
                return getValueAt(0, column).getClass();
            public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
                Component c = super.prepareRenderer(renderer, row, column);
                TableColumnModel tcm = table.getColumnModel();
                Object result = getValueAt(row, tcm.getColumnIndex("Value"));
                if(result instanceof Integer)
                    if(((Integer) result) == 23)
                        c.setBackground(new Color(0, 255, 153));
                        c.setForeground(Color.BLACK);
                        if(column == 0)
                                // I would like to do a CELL ALIGNMENT for this particular condition.
                                // setHorizontalAlignment() does not exist for the object c (Component).
                    else
                        c.setBackground(Color.WHITE);
                        c.setForeground(Color.BLACK);
                        if(column == 0)
                                // I would like to do a CELL ALIGNMENT for this particular condition.
                                // setHorizontalAlignment() does not exist for the object c (Component).
                if(table.isRowSelected(row))
                    c.setBackground(Color.BLUE);
                    c.setForeground(Color.WHITE);
                return c;
        JPanel panel = new JPanel();
        JScrollPane sp = new JScrollPane(table);
        panel.add(sp, BorderLayout.CENTER);
        frame.setContentPane(panel);
        frame.pack();
        frame.setVisible(true);
}Sorry for bringing this up again, but I am having a hard time trying to "align" a single "cell". In the code that I have provided, I tried to find a method from the Component object for setHorizontalAlignment() hoping to make this call:
c.setHorizontalAlignment(SwingConstants.RIGHT);
However, it does not exist. How would I go about setting the alignment for an individual cell? I've searched the forum for "cell alignment" and found some information about using a DefaultTableCellRenderer, but I'm not sure how to merge that with the existing code that I currently have.
In this thread: http://forums.sun.com/thread.jspa?forumID=57&threadID=659910 , camickr pointed out that I can use the row and column variables to find which cell to align, however once I've found the particular cell that I'd like to align, what do I do next? The component c does not have a method to set alignment in this scenario.
Thanks again,
Brianiak

You - the programmer - know that the component in question will be a label of some kind. The compiler, however, does not. As far as javac is concerned, the component could be, say, a 3D animation, in which case setHorizontalAlignement would be illegal.
In order to share our runtime knowledge with the compiler, we have to use some explicit casting:
(JLabel)c.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);Note that this will lead to runtime errors if our component is not an instance of JLabel, so it's a good idea to surround the code with:
if (c instanceof JLabel){
}

Similar Messages

  • How to disable single cell in table control.

    Hi my requirement is to disable single cell in the table control. Please let me know How to do this.
    If possible please provide good module pool examples.
    Harish

    Hi,
    I´m not quite sure if this is gonna work. You have to make a loop over the screen and then you can change some characteristics of it, which includes the Input option:
      LOOP AT SCREEN.
        IF screen-group1 = 'ABC'.
          screen-input = '0'.
          MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
    I´ve used this code for selection screens but could help you. Check in SE11 all options for SCREEN.

  • How could I insert just a single cell in a table (not an entire extra row or column)?

    I am having trouble making an easy edit. I need to insert an a 'CELL', but I am only being given the option to insert an entire 'ROW' or 'COLUMN'. I would like to just insert a cell and have the rest of the content below it move accordingly. Please help!

    There's no way to set it so that you're just inserting a cell and everything moves along after that cell?
    Simple answer is "No." Sorry.
    InDesign tables are not good for juggling data. If you have a project that requires single-cell-insertion on a regular basis, I suggest doing your table outside of InDesign in an app with easier table-cell-juggling tools (Excel comes to mind here) and then perfecting you use of table and cell styles so that it's easy to update. It'll always be a hassle of some kind, of course, but the hassle can be minimized.

  • Creating table, two cells side by side but alignment in one cell throws off the other!

    Hello,
    I have a website that I am trying to display a table with two columns side by side and one column at the bottom.
    so I use the following:
    <table>
    <tr>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    </table>
    My problem is that I can't get the alignment to work right wit the first two <td> columsn that are side by side.  i put text in both and an image but it doens't align properly even without the image. Every time press <return> it adjust the alignment in the other column. as you can see below, it doesn't align correctly. I can't get it to work right.  images don't align, button doens't align, and the text on top doesn't align either.
    If I press <return> in the right column at the bottom, then it moves the left column down and still doesn't align (auugh!)
    Here is my code:
    <table width="685">
                             <tr>
                             <td width="338" class="vline">
                             <p class="indentmain">Point 7.4 Service Pack 2 is available! </p>
                               <p class="indentpar">Point 7.4 SP2 (release date March 30, 2011), includes the newly required Anti-Steering disclosure along with other necessary compliance updates and functional enhancements<img src="../images/SideBar/customer_care.jpg" alt="" width="162" height="87" hspace="6" vspace="6" align="right" /></p>
                               <p class="indentpar"><strong>MyCalyx Administrators: </strong>Be sure to log into your <a href="https://www.mycalyx.com">MyCalyx</a> account and update the user's version of Point to 7.4SP2.</p>
                               <p class="indentpar"><strong>
                               Click</strong> for comlete release notes.</p>
                              <p class="indentpar">
                                 <input type="button" class="button_Download" value="Download Instructions" onclick="window.open('http://www.calyxsupport.com/downloads/index.htm?tab=1&col6=open#CollapsiblePanel6#TabbedPa nels1')" />
                               </p>
                              <p class="indentpar"> </p>
                             </td>
                             <td width="335">
                             <p class="indentmain">PointCentral 7.3 Server Update</p>
    <p class="indentpar">The PointCentral 7.3 Server Update is available for download, (released March 24, 2011). The server update addresses field mapping issues that causes data fields to <img src="../images/SideBar/page_in_book.jpg" alt="" width="162" height="87" hspace="6" vspace="6" align="right" />inaccurately appear when generating reports and adding the owner's title policy setting under the Utilities menu. </p>
                               <p class="indentpar"> </p>
                               <p class="indentpar"><a href="http://kb.calyxsupport.com/kb/article.php?id=557">Click here</a> for release notes.</p>
                               <p class="indentpar">
                                 <input type="button" class="button_Download" value="Download Instructions" onclick="window.open('http://www.calyxsupport.com/downloads/index.htm?tab=1&col6=open#CollapsiblePanel6#TabbedPa nels1')" />
                               </p>
                               <p class="indentpar"> </p>
                               </td>
                             </tr>
                             <tr>
              <td height="8" colspan="2"></td>
                </tr>
                            <tr>
                              <td style="display: inline" height="5" colspan="2"><img border="0" src="/images/bottom_border.gif" width="100%" height="5"></td></tr>
                           <tr>
                              <td height="8" colspan="2"></td>
                </tr>
                <tr>
                <td colspan="2"><p class="indentmain">What to look for in Point 7.4</p>
                  <p class="indentpar">There have been peculiar incidents with the Transmittal Summary and calculations on the Fees Worksheet, such as transfer taxes and up-front mortgage insurance. You can prevent or avoid such mishaps by understanding the  process that provoke or produce these incidents.</p>
                  <p class="indentpar">We also understand that since the release of MyCalyx.com and the non-distribution of an installation CD, installing and upgrading Point is new but still simple and easy, but just takes some getting use to.</p>
                  <p class="indentpar">We have provided a list of commonly used articles to help guide you through using MyCalyx.com and avoiding irregularities with the Fees Worksheet.</p>
                  <p class="indentpar">
                    <input type="button" class="button_Download" value="Download Instructions" onclick="window.open('http://www.calyxsupport.com/downloads/index.htm?tab=1&col6=open#CollapsiblePanel6#TabbedPa nels1')" />
                  </p></td>
                </tr>
                             </table>

    Tables work that way, that's why CSS styling is preferred for layouts.
    http://apptools.com/examples/pagelayout101.php
    If you must use tables, try nesting tables inside cells of an outer table .

  • How do I change the background of a single cell or a row in a table?

    How do I change the background of a single cell or a row in a
    table? I doesn't seem to be letting me do that.

    Are you using the latest DW? If so, then it isn't letting you
    because
    bgcolor is deprecated and shouldn't be used.
    The correct way is to use css to define the background of a
    cell
    CSS:
    .blackcell {background-color: black;}
    HTML:
    <td class="blackcell">whatever in the cell</td>
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    ~ Template Customization ~
    http://www.csstemplates.com.au
    Spry Widget Examples
    http://www.dreamweaverresources.com/spry-widgets/
    "dm25" <[email protected]> wrote in message
    news:f4jr5h$luu$[email protected]..
    > for some reason that doesn't always work. When I click
    inside a cell, it
    > doesn't give me an option to change the background
    color.

  • How to get space between two values in a single cell of a table.

    hello,
            how to get space between two values in a single cell of a table.
    thanks a lot.
    kailash.

    sorry i got the answer.

  • Table sIngle Markable cell

    Hi friends,
    I got a task to find the X and Y coordinates of a table cell  using Table Single Markable cell.......
    Is it possible to get X,Y coordinates  using the above API.....
    Is there any alternative for this......
    please code me and help me....
    Thanks &Regards
    Shravan kumar

    Hi shravan..
    Go thru this link..
    https://help.sap.com/javadocs/NW04S/current/wd/com/sap/tc/webdynpro/clientserver/uielib/standard/api/IWDTableSingleMarkableCell.html
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/9214b1e5-0601-0010-fdb0-ec32d43b06e0
    Urs GS...

  • Having difficulty resizing a single cell width in a table

    Hi
    I have a table in a Pages 09 document with several different rows and columns. I'm having real trouble trying to resize a single cell - that is I have a row split into two columns and the left column won't shrink very far so I have loads of empty space after the text I have in that column which is a pain as it looks untidy. I've selected that cell and have no option to adjust column width in Table Inspector, I've selected 'Automatically adjust width to text size' and that's making no difference and trying to manually move the cell wall to the left makes no difference - it'll go so far and then no more.
    What's just as annoying is that I have exactly the same 'one row/two columns' format just below this row and that left column cell shrinks even less, meaning I have a staggered columns set up going on down my table which looks daft.

    I am unable to reproduce this behaviour.
    You may activate the "Show Invisible Characters" feature which will perhaps reveal the existence of extraneous chars.
    If it's not that, I would be interested to receive this table.
    Of course, remove personal infos from the document before sending it to my mailbox.
    Click my blue name to get my address.
    Yvan KOENIG (VALLAURIS, France) mercredi 31 mars 2010 22:07:25

  • Insert or delete single cells

    How do I insert or delete a single cell?
    For example, I want two columns of text. aligned horizontally, and, separated by a blank column.
    The two text lists have been created in other applications.
    So I copy list1, and paste it in cell C7.
    Then I copy list2, and paste it cell G6.
    oops. Now the lists are not aligned horizontally.
    The easiest way to align the lists is by either delete a single cell in column C or insert a single cell in column G.
    But I can't find the option to add/delete single cells.
    Does that option exist in Numbers? If so, how/where?
    Thanks,
    AJ

    AJ,
    My first thought on reading your post was: why are you using a single table for two side-by-side lists? If you had used two single-column tables you could use Delete Row or Insert Row to do what you want.
    pw and John both gave you perfectly good solutions, and I just wanted to add my two cents worth. I don't see much value in the Add/Delete Cell feature that you are looking for. The action never ends there because there's always a followup question as to what you want to do with the data to the right of and below the affected cell. So, it hasn't saved you any real time.
    Numbers has a very handy and secure method for moving a range of data. Highlight the range that you want to move. Then, Edit > Mark for Move. Now, click in the new starting location and Edit > Move.
    There you go; several ways to recover from the inevitable oops. Depending on how soon you discover your mistake, Command-Z is probably the easiest fix.
    Jerry

  • Cell alignment problems

    hi, im currently working on a website with dreamweaver, its
    only the 2nd html site ive ever made.
    both sites have been photography portfolios, so involve
    thumbnailed galleries. i figured it would be easiest to use tables
    to create the pages, as the the images are different sizes (some
    landscape, some portrait etc). i used css for properties of cells.
    problem is, when i move from one page to another in the
    browser (seems to be every browser, but some are worse than
    others), the cells appear to move. some of them have borders so
    this is quite obvious.
    am i missing something glaringly obvious? i find it so
    frustrating, i have tried adjusted the cell widths through css and
    single cell properties but neither seem to make the slightest
    difference. it appears the content that is in each cell determines
    the width of it in the browser, how can i control this so i can
    maintain uniform alignment throughout the site?
    many thanks in advance for any advice whatsoever

    With a single table like that, you'll experience the size
    shifts. You
    may want to use a single nested table for the content.
    Outer table - 3 rows
    top row, colspan 2
    middle row, thin left cell for navbar, wide right cell to
    hold nested table
    bottom row, colspan 2
    Set explicit widths for the middle row cells.
    In the middle row right cell, place a nested table with the
    page content.
    Another option is to go "tableless" and just use CSS for the
    layout.
    (PS - I didn't even notice the buttons on the left for a
    while. I stared
    dumbly at the page wondering how to get to the next page. The
    buttons
    are so dim they are difficult to see against the black
    background.
    Depending on the angle of my LCD screen, sometimes they
    disappear entirely.)
    Alec
    Adobe Community Expert

  • I prepare chronologies in word, and i am trying to do the same in pages using tables and cells. But somtimes i need a cell to wrap onto the next page but I can't work out how to do it - any suggestions would be greatly appreciated

    I prepare chronologies in word, and I am trying to do the same in pages using tables and cells. But sometimes I need a cell to wrap onto the next page because the contents are bigger than the page or the space left on the page,  but I can't work out how to do it - any suggestions would be greatly appreciated

    brendanfromsydney wrote:
    What are the different opinions on why pages should not achieve this?
    As far as I know, Apple is free to choose to offer this or that feature.
    They never said that they want to clone Word or even compete with it.
    Differences between tables in both worlds are numerous.
    In Pages (or Numbers)
    - we can't sort a single column
    - we can't sort by row
    - we can't insert or remove a single cell
    - a cell can't cross pages boundaries
    If I understand well these design choices match :
    ++-+-+-+-+-+-+-+-++
    Apple Human Interface Guidelines:
    Apply the 80 Percent Solution
    During the design process, if you discover problems with your product design, you might consider applying the 80 percent solution‚ that is, designing your software to meet the needs of at least 80 percent of your users. This type of design typically favors simpler, more elegant approaches to problems.
    If you try to design for the 20 percent of your target audience who are power users, your design may not be usable by the other 80 percent of users. Even though that smaller group of power users is likely to have good ideas for features, the majority of your user base may not think in the same way. Involving a broad range of users in your design process can help you find the 80 percent solution.
    +-+-+-+-+-+-+-+-+-++
    Yvan KOENIG (VALLAURIS, France) jeudi 9 juin 2011 16:03:52
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.7
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me?

    I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me? The final result would be a spreadsheet telling there were 8 people from 20 to 39 years old, 14 peolple from 40 to 59 and so on...

    jpqcampos wrote:
    This appears to be an 'input form' using 'Radio Buttons' to select the category. Neither of these features are supported in Numbers '09.
    You can input the data on one table and summarize it on a second table, but the input table will continue to hold data for each event.
    And by using the Reorganize button, you can hide all but two rows of that table to approximate the appearance and performance of an input form.
    Here are the two tables, Data on the left and Summary on the right. Notes below.
    The grey-filled columns in both tables are 'working' columns, and may be hidden (as shown in the image below).
    Data table:
    D1 contains the word "TRUE" (in capital letters). (This row is always shown.)
    D2 is empty, or may contain any value except "TRUE" (This row is always hidden under the Reorganize rule.)The rest of Row 2 of this table requires the data shown: a number outside the range to be counted (999), and two checkboxes, both checked.
    D3 (and filled down the rest of column D):   =AND(OR(B2,C2),NOT(OR(B3,C3)))
    The formula returns TRUE only for the first unused row in the table (ie. the first row for which neither checkbox has been checked)
    Summary table:
    Column A contains labels for the age ranges to be counted.
    Column B contains the same information in the form necessary for the formulas in columns C and D. They need a numeric value, and that value must be the largest acceptable value in the range to be counted.
    C2 (and filled right to column D, then both filled down to row 5):
        =COUNTIFS(Data :: $A,"<="&$B,Data :: B,TRUE)-SUM(C$1:C1)
    Two changes from the previous example:
    COUNTIFS is used to separate the Native and Foreign counts as well as the age range to be counted.
    The amount subtracted from each result is the SUM of the earlier results, and includes the text value in the first cell of the column (which is interpreted by SUM as a zero).
    See note below regarding my earlier formula.
    When the greyed columns are hidden and the checkbox in the Reorganize pane is checked, the two tables will appear as shown below:
    Close the reorganize pane, and the 'data entry form' is ready to use.
    To use, enter the age first, then check one of the boxes.
    As soon as one box is checked, the row will be hidden, and the next (unused) row will be shown.
    Regards,
    Barry
    Note regarding formula in my earlier post:
    The earlier formula will give erroneous results as it subtracts only the count directly above it from its count of persons in the age range 0-n.
    In E2 of that table, replace "-E1" with "-SUM(E1:E$1)
    Fill down to E8.
    Ignore the instructions (in that post) following "Fill down to E8."
    B

  • Show top n sum of a dimension in a single cell

    Hi experts,
    is it possible to show the sum of top n values in a single cell?
    example:
    Table shows (top 3)
    USA___________180
    Germany_______150
    Italy___________100
    Sum___________430
    single cell should show
    430

    Create a variable "rank" as
    =Rank([Measure])
    Then, in the standalone cell, enter the formula:
    =Sum([Measure] Where ([rank] < 4))

  • How do I outline a single cell in a numbers spreadsheet

    I am trying to emphasise the borders of a single cell in a numbers spreadsheet;  I follow all the instructions I can find in mac help, they just don't make any difference.  I may be ancient, but I can usually suss things out in time; this baffles me.  However, I do realize I may have blundered into the wrong type of help forum here.

    To place borders around a cell in Numbers -
    Make sure the cell has been selected, i.e. is the active cell.
    Click the Inspector tool in the Toolbar -
    Then click the Table inspector icon in the Inspector window's toolbar -
    In that screen, look down to the section "Cell Borders"...
    Click the button for full border (arrow in pic above) -
    Adjust the color of the border as needed for visibility (oval in pic above) -
    And then you may need to adjust the line weight (thickness) to get it visible on-screen. To do that, click the dropmenu in that section showing "Thin" and select the next item underneath "thin" in the menu. This will make the item just to the right of that menu active - you can then use the arrow-buttons to make the line weight thicker. Although the thinnest setting (0.25 pt) may print okay, on some screens it just doesn't show - especially of the border color has not been set to a hard black. Making it thicker can help in viewing it on-screen.

  • Make the link from the single cell of Bex Report and the image of bill

    Hi guys,
    my client scan every bill and archive the image by File.net technology.
    In our Bex Report we have the Bill number and we want to make the link from the single cell and the image of bill.
    The possible paths to solve the problem are:
           Replicate the image in BW and crate a link from the single cell and the image of document.
           Create an URL link from the single cell and the image of document archived on File.net server.
    In witch way we can to implement the two paths?
    Thank you.
    Alessandro

    Hi Alessandro,
    Have you seen "How To…Enhance your Web Query with the Table Interface"?
    You can find it in media library:
    https://websmp105.sap-ag.de/~form/sapnet?_SHORTKEY=01100035870000194044
    Best regards,
    Eugene

Maybe you are looking for

  • Application Update issue

    Hi Friends, I have one application on app store which I just have uploaded  with v1.0. where I got one problem that the one xib missing the UITestfield. so I updated the code and uploaded the application again on the app store(v1.1). In both case app

  • Outlook 2013 does not send / receive mails but connected to Exchange server

    HI All,  Outlook 2013 displays connected message but when compose and send a mail, the message hangs for more than an hour. Yes if I restart the outlook, the message is sent.  Otherwise the message will lag for hours. Even I am not able to receive it

  • Get a String of XML from an XMLBean

    I create XMLBeans based on a schema, set some values as follows: SomeSchemaDocument someSchemaDocument = SomeSchemaDocument.Factory.newInstance(); SomeSchema someSchema = someSchemaDocument.getSomeSchema(); someSchema.setCustomerNumber(customerNumber

  • Dynamic field labels in table control

    Hi experts,     My requirement is to display dynamic field labels in table control can we do this. I am much aware that we can do it in alv_grid. Please let me know. Thanks in advance. Sri

  • Scrollable text frame

    Hello, I have a page with a fixed size and would like to make a scrollable text in a frame, as I do this in muse? It's about this site, I want to create in Muse: http://www.kayser-stoneworks.de/impressum.html Thanks for help, greeting martin