Simulating one column using two columns in a JTable

What I need to do is "join" the two first columns of a JTable...
What do I mean by saying "join" ?
I want to make dissapear the right border of the first column, and the same thing for the left border of the second column, also do both things for the column headers of that two columns.
All that to simulate having one column when there's actually two differents columns.
How can i do that ? Thanks !

Make a TableModel that filters your original table model.
See JTable.setModel.
public class MergedColumnsTableModel extends javax.swing.table.AbstractTableModel
     javax.swing.TableModel model;
     int[] columnSpans;
      * Assume for simplicity that model does not change (no columns inserted/deleted).
     public MergedColumnsTableModel(javax.swing.TableModel model) {
          this.model = model;
          columnSpans = new int[model.getColumnCount()];
          for (int columnIndex = 0; columnIndex < columnSpans.length; ++columnIndex) {
               columnSpans[columnIndex] = 1;
     public void merge2(int columnIndex) {
          int leftSpan = columnSpans[columnIndex];
          int rightSpan = columnSpans[columnIndex + leftSpan];
          columnSpans[columnIndex + leftSpan] = 0;
          columnSpans[columnIndex] += rightSpan;
     public int getRowCount() {
          return model.getRowCount();
     public int getColumnCount() {
          int n = 0;
          for (int i = 0; i < columnSpans.length; ++i) {
               if (columnSpans[i] != 0) {
                    ++n;
          return n;
     public Object getValueAt(int row, int column) {
          int n = 0;
          for (int i = 0; i < columnSpans.length; ++i) {
               if (columnSpans[i] != 0) {
                    if (n == column) { // We are at the column
                         return model.getValueAt(row, i);
                    ++n;
}

Similar Messages

  • Splitting one column into two columns

    Hi,
    How to create two columns in one column header using JTable swing concept in java.
    Thanks in advance

    [http://forum.java.sun.com/thread.jspa?threadID=488822&messageID=2297054]
    you can use MultiLineHeaderRenderer class for this purpose. search for that class and examples
    sunil

  • Displaying the values from a single column into two columns???

    hi buddies.....I've a table "Stock" and its fields are:
    Date, Invoice#, prod_id, sal_qty, pur_qty, rate, status
    The "rate" column stores the rate value on which a product was sold or purchased and "status" column values are like "S" for Sale,"OP" for opening and "P" for purchase.
    The problem here to me is that I'm unable to pick the purchase & sale rate of a product based on the status either "S" or "P". Is it possible to pick the purchase rate of a product sold between a specified limit of dates??? and show both sale & purchase rates in two separate columns in the result sets for a given product in a specified duration. The resulte set format should be like this:
    Prod_id Sale_Rate Pur_Rate

    Dear Dmitri,
    Let me tell u my case more elaborately so that u can have a better insight on my problem. I've a Stock table to which I'm trying to use to calculate current stock quantity, its value and profit per sale transaction. It has following simple description.
    Stock_Table:
    Invoice#     Date     Product     Batch# Sale_QTY     Pur_QTY     Rate Status
    Pur-001     01/01/05     Asprin          AB123      0     100           10 OP --(Opening)
    Pur-002 02/01/05     Paracetamol CD456          0     150          15 OP
    Pur-002 03/01/05     Menthol XY333           0     80          7     OP
    Pur-003     01/01/05     Asprin          ZZ990           0     50          8     P ..(Purchase)
    Sale001 02/01/05     Asprin          AB123           10     0          2     S
    Sale001 02/01/05     Paracetamol      CD456           5     0          16     S ..(Sale)
    Sale002 04/01/05     Asprin          ZZ990           6     0          10     S
    Sale002 04/01/05     Paracetamol      CD456           7     0          20     S
    Sale002 04/01/05     Menthol      XY333          4     0          10     S
    From this design can u calulate the difference of sale & purchase rate of a product during a range of dates(which is the Profit)? i.e firstly pick a sale transaction and then minus the purchase rate of the product from the sale rate in that sale transaction by looking at the product name and its batch number.
    While solving this case, please keep in mind that I'm using Oracle 8.0 which doesn't support inlined Sub-Query(a query within FROM clause). So giving u a hint(although I'm not genious enough;), I tried the Self Join at Stock Table by picking the sale rows at first and then purchase rows afterwords by giving this table two different names. I also tried the following query by joining the Sale Table with Stock Table. Is it the right way I'm heading towards???
    SELECT S.Sale_Date, SD.Invoice#, SD.Product, SD.QTY, SD.Rate Sale_Rate,
    ST.Rate Pur_Rate, ST.Product
    FROM Invoice_Master S, Invoice_Detail SD, Stock ST
    WHERE S.Invoice# = SD.Invoice#
    AND ST.Status IN('OP','P')
    AND ST.Product = SD.Product
    AND S.Sale_Date BETWEEN :From_Date AND :To_Date
    AND SD.Product = P.Product
    ORDER BY S.Sale_Date

  • Can two user accounts of one computer use two different Mac ID accounts?  I'd like to keep separate accounts for movies, music etc.

    I have a Mac Air running 10.8.5, with two users on it.  I'd like to keep separate Apple store accounts accounts for the two users, as we have separate music, movies, books etc.  To date, we've had separate computers, but now will share the one computer.  But when the second account is signed in and we try to sign in to the I-tunes store, or authorise the computer with the second account, the response is "the I-Tunes store is not available" or "we cannot fulfil your request at this time".  Togetherness is nice, but I'd prefer to have some privacy.

    Hi Harrike2000,
    Welcome to Apple Support Communities.
    It sounds like you’re running into an iTunes Store connection issue in one of the user accounts on your MacBook Air, and you want to know if the issue is related to using multiple Apple IDs or user accounts.
    You can use multiple user accounts and Apple IDs with one computer, see this article for more information:
    How to use multiple iPhone, iPad, or iPod devices with one computer - Apple Support
    For the issue connecting to the iTunes Store, try the suggestions in the article linked below.
    Can't connect to the iTunes Store - Apple Support
    Troubleshoot issues on a Mac
    If you haven't been able to connect to the iTunes Store, a software conflict or your Internet service provider (ISP) may be blocking your access.
    Update iTunes and Safari to the latest version.
    If you have a firewall, your settings may be preventing you from connecting to the iTunes Store. Follow these steps to configure your firewall.
    You may need to reset your keychain. Connection issues are occasionally caused by keychain issues. Learn how to use Keychain First Aid to resolve any issues with your keychain.
    If you're receiving a specific error message, follow these steps.
    If the issue still persists, contact your Internet service provider and confirm that these ports and servers are enabled over your network.
    Learn more
    If the steps above didn't resolve your issue, be sure that your specific alert isn't listed as a possible iTunes Store error. Then, if your issue is still unresolved, follow these steps.
    Cheers,
    -Jason

  • One account using two computers

    I know there have been a few posts about this. But I can't seem to find a straight answer. Keeps talking about a PC and a Mac.
    I have two macs, one at work and one at home.
    1. When I come home, I want to work on my home computer. Do I have to make sure all the programs are closed on my work computer, to use Creative Cloud at home?
    2. Im thinking about getting a new computer in a few months, can I easily then deactive my old computer and install the cloud on my new machine?

    Question # 1 answer:
    You do not have to make sure the programs are closed on the work computer. The license agreement is that you will not use the software on two computers at the same time.
    Question # 2 answer:
    As Amit has answered above. You have two activations. When you try to activate on a third computer you will be asked about deactivating on the others.

  • One iPlanet using two application servers?

    Can anyone help, is it possible for one iplanet 6.0 instance using/connecting two application servers (i.e. one is JRun server, another is Webspere server) at the same time?
    If so, how to do it?

    I don't see why not. I have had the same webserver talking to both iplanet 6.5 and sunOne 7. As both the application servers will connect vias a plugin I would suggest you follow the instructions for both application servers and see what happens.

  • I use two apple tvs, when useing mulity speakers on computer plus two tvs the audio plays on all but only video on one, i use two apple tvs, when useing mulity speakers on commputer plus two tvs the audio plays on all but only video on one

    i use 2 apple 2nd generation tvs, on mulity speakers, computer and 2 tvs have audio but only one has video, why does the video not play on all at the same time

    Welcome to the Apple Community.
    I'm not entirely sure whether you're asking if it should or why it doesn't. To cover the first point it isn't supposed to, so your set up is working correctly.
    As to why not I'm not absolutely sure, it isn't a bandwidth restriction as whilst I can't be certain that all our 6 Apple TVs have all been streaming video at the same time (when initiated from the Apple TV), I believe at least 4 have on occasions. So I imagine it's another technical limitation that I'm not aware of, perhaps it's a synchronisation problem, who knows.

  • Using two editor instances within JTable

    Hello,
    I'm struggling around using component editors within JTable. E.g. selectAll text on entering a JTextField cell or immediately raising the popup while entering a JComboBox cell.
    In my analysis most of these problems arises due the re-use of the cell editor.
    The event sequence is doing things in the context of the old cell while preparing the editor for the new cell has already been started.
    Because it is the same component and some things are bound deep inside the L&F it seems not easy to handle them properly.
    Just an idea from me is to avoid such problems by working with two instances for the editors in general. This should avoid all problems coming out of overlapping event processing. (To provide each cell with an own component is of course no solution)
    Any comment on such an approach?
    Thanks in advance
    Wolfgang R.

    No, it wasn't the custom JTable extension.
    By entering a cell a popup will be shown for a short moment. This is only by using Windows L&F (not Metal). Within the L&F a togglePopup() is called which may cause this problem.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.util.EventObject;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.UIManager;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    public class JTableExt extends JTable {
         public static class ComboBoxEnumRenderer extends JComboBox implements
                   TableCellRenderer {
              public ComboBoxEnumRenderer() {
                   setEditable(false);
                   setBackground(Color.WHITE);
              public Component getTableCellRendererComponent(JTable table, Object value,
                        boolean isSelected, boolean hasFocus, int row, int column) {
                   this.removeAllItems();
                   this.addItem(value);
                   return this;
         public static class ComboBoxEnumEditor extends DefaultCellEditor {
              private static String[] values = null;
              public ComboBoxEnumEditor() {
                   super(new JComboBox());
                   values = new String[50000];
                   for (int i = 0; i < values.length; i++) {
                        values[i] = "row_" + i;
              public Component getTableCellEditorComponent(JTable table, Object value,
                        boolean isSelected, int row, int column) {
                   JComboBox combo = (JComboBox) getComponent();
                   combo.removeAllItems();
                   for (int i = 0; i < values.length; i++) {
                        combo.addItem(values);
                   combo.setSelectedIndex(0);
                   return super.getTableCellEditorComponent(table, value, isSelected, row,
                             column);
         public JTableExt() {
              super();
              init();
         // invoke editor on cell entry
         public void changeSelection(final int row, final int column, boolean toggle,
                   boolean extend) {
              super.changeSelection(row, column, toggle, extend);
              if (editCellAt(row, column))
                   getEditorComponent().requestFocusInWindow();
         private void init() {
              setDefaultEditor(Object.class, new ComboBoxEnumEditor());
              setDefaultRenderer(Object.class, new ComboBoxEnumRenderer());
         private static void setUI() {
              String lnfName = "";
              //lnfName = "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel";
              lnfName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
              try {
                   UIManager.setLookAndFeel(lnfName);
              } catch (Exception exc) {
         public static void main(String args[]) {
              try {
                   setUI();
                   javax.swing.JFrame frame = new javax.swing.JFrame();
                   frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                   frame.getContentPane().setLayout(new BorderLayout());
                   final JTableExt demo = new JTableExt();
                   Object[][] data = new Object[30][1];
                   demo.setModel(new DefaultTableModel(data, new String[] { "first column" }));
                   frame.getContentPane().add("Center", new JScrollPane(demo));
                   frame.setSize(600, 600);
                   frame.setVisible(true);
              } catch (Throwable t) {
                   System.exit(0);
    //end

  • Learning to use lookup transformation - match value in one of two columns

    Im a little new to using lookup transforms.  Been reading a bit, but using two columns is throwing me off.
    Have a dataflow with the source having a column I want to use to lookup in a table in another DB.  The match could be in one of two columns in that table.  
    If a match is found, I need a different value from the lookup table added to the source flow that is going into the destination.
    How can I match on one of two columns in the lookup table, and use a totally different column added to the final input going into the destination ?  
    In the Lookup configuration, I can set the lookup operation to replacing the value in the source, but I want EITHER value match from the two columns from the lookup table to go into the value that will go into the destination.
    With TSQL - I would use a case statement and compare the source column to BOTH of the lookup table columns.

    You can handle this within single lookup using below query
    SELECT CASE WHEN <condn1> THEN Field1 ELSE Field2 END AS lookupField,
    CASE WHEN <condn1> THEN Field3 ELSE Field4 END AS MatchField
    FROM Table2
    Then just do single relationship with LookupField and select MatchField to be aded to output
    the condition will specify your fields value condition based on which you determine which column to be matched against
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Looking for a two-column CSS layout

    I am looking for a two-column CSS layout that is centered
    with blank space
    on the sides, so the layout does not expand across the entire
    screen, but
    instead uses a portion of it (such as 75%). The left column
    would be for
    navigation and I haven't decided if I want it to be liquid or
    fixed, but the
    right column for content would be liquid. There would also be
    a heading div
    and navigation div across the top and a footer across the
    bottom.
    While looking for sample sites I keep finding ones that use
    three columns,
    and I'm worried that if I remove the third column that the
    layout will break
    at some point, even if I don't see it in my test browsers.
    I'm also
    discovering that some of the sample pages out there don't
    respond well when
    I resize the browser window. The columns don't have a minimum
    width or they
    stack on top of each other at some point.
    There are so many different techniques to use when designing
    a layout with
    CSS, some better than others, that I thought maybe some
    people here may
    already know what's tried and true and what should be
    avoided. Are any
    layouts robust enough to allow a third column to be added at
    a future date
    if needed? I also like the idea of putting the content div
    first in the
    code, to improve search engine indexing and also to aid those
    who may be
    using a screen reader, but if that feature makes the coding
    much more
    complex then I could see why I might avoid it for now.

    Sorry Nancy, I didn't see your post for some reason. At least
    we agree (o:
    Jo
    "josie1one" <[email protected]> wrote in message
    news:g4tv32$57f$[email protected]..
    >I have DW8 and am very happy with this:
    >
    http://projectseven.com/products/templates/pagepacks/cssmagic/index.htm
    >
    >
    > --
    > Jo
    >
    >
    > "Matt" <[email protected]> wrote in message
    > news:g4tg96$isq$[email protected]..
    >>I am looking for a two-column CSS layout that is
    centered with blank space
    >>on the sides, so the layout does not expand across
    the entire screen, but
    >>instead uses a portion of it (such as 75%). The left
    column would be for
    >>navigation and I haven't decided if I want it to be
    liquid or fixed, but
    >>the right column for content would be liquid. There
    would also be a
    >>heading div and navigation div across the top and a
    footer across the
    >>bottom.
    >>
    >> While looking for sample sites I keep finding ones
    that use three
    >> columns, and I'm worried that if I remove the third
    column that the
    >> layout will break at some point, even if I don't see
    it in my test
    >> browsers. I'm also discovering that some of the
    sample pages out there
    >> don't respond well when I resize the browser window.
    The columns don't
    >> have a minimum width or they stack on top of each
    other at some point.
    >>
    >> There are so many different techniques to use when
    designing a layout
    >> with CSS, some better than others, that I thought
    maybe some people here
    >> may already know what's tried and true and what
    should be avoided. Are
    >> any layouts robust enough to allow a third column to
    be added at a future
    >> date if needed? I also like the idea of putting the
    content div first in
    >> the code, to improve search engine indexing and also
    to aid those who may
    >> be using a screen reader, but if that feature makes
    the coding much more
    >> complex then I could see why I might avoid it for
    now.
    >>
    >
    >

  • Two column text wrap

    I'm using CS5 and I'm preparing a book that uses two columns. I have some photos that extend from one column into the other. When I wrap text around those photos one of the columns wraps fine but the other column does not. It wraps with a large white space, that is, both columns do not wrap equally. A friend of mine tells me this problem has persisted in previous versions of InDesign.

    function(){return A.apply(null,[this].concat($A(arguments)))}
    this is 100% normal, expected, and nasty behavior.
    !? (in particular on the "expected"...)
    Is this area the problem?
    What happens if you force some text in the last line of the caption -- say, a Right Indent Tab, and if that's not enough, followed by a [None] colored exclamation mark?

  • Best way to have an image span two columns in a CSS layout?

    My homepage is a typical fixed width three column layout. For the inside, content pages, I basically need the same layout except I need to have an image that spans the left and center columns at the top. Below the image, the left and center columns should continue on. The right column should not change at all m
    My first thought is to start with a two column layout where the left column would contain the image. Then, I would divide the left column into two columns that would start below the image, using a top margin or perhaps another appropriate positioning attribute.
    But before I create a completely new layout for these pages, I thought I'd check and see if there may be an easier or better way to do this. any ideas?

    Thank you, Thank you, Thank you for both responses. But I have to say I went with the AP div solution. In either case, I would have needed a second layout but this way was a much simpler modification to the three column index page. I did try it both ways as I'm still a-learning. I'm finally getting to the point where when I set or change a setting - especially positioning attributes like margins, the outcome is what I expect. I have also experimented enough where I see there is often more than one way to produce the desired result. However, I'm afraid that in many of these cases I can't explain why one method might be better, or preferred over another. Or if in some instances it simply doesn't matter, unless the final issue is arriving at the most efficient and lightest amount of code required to do the job (that's what I call the Holy Grail in programming and scripting).
    As an audio engineer as well, I'm reminded of certain discussions on how to achieve the best sound for this or that, and after going round and round about effects, the science of acoustics, which plug in works best and for what, often the only thing ever really settled upon is "just go by what sounds the best to you". I digress.
    So using the AP div in this case, what, if anything is the downside? Does it matter that its content as well as the rest of the page will be dynamic? I wouldn't think so. Might there be issues with older browsers or mobile browsers? The former is not a concern, but the latter is. Might I be tempted to use an AP div at another time because it's so easy to implement, but then may not be an appropriate use? I think I can properly evaluate that if and when the time comes.
    Am I just over-thinking all this? : )
    Thank you again!
    Edited to add: I wanted to mark both responses as correct, but it wouldn't let me do it. No offense I hope!

  • Problem with two-column layout

    Hello,
    I've done table-based layouts for several years, but I'm
    trying to switch to CSS. I still have a lot to learn...
    I'm trying to create a web site as a favor for a friend. She
    hasn't figured out what she wants yet, so I've just been creating
    some pages using canned designs. I created one using "Two-column
    left nav" under Dreamweaver's "Page designs (CSS)":
    http://www.alcie.org/demo2/
    I want a fixed-width left navigation column and a fluid
    content column.
    I ran into several problems with the original design. The
    most notible was that if I changed the browser window width, both
    the content and nav columns would resize. I didn't want that, so I
    set "navBar" width: 150px. That worked, but if I make the window
    too narrow, the content starts to overlap the navigation column in
    Firefox 1.5.0.6, and the navigation DIV drops to below the content
    in IE 7 rc (I think) 3 and IE6. I tried removing the width
    altogether, but that made things worse.
    What is wrong with this picture? Is there a cleaner way to
    solve my problem?
    Thanks.

    > Is there a cleaner way to solve my problem?
    Yes - dump that layout. It's too quirky. Go here and grab one
    http://www.maxdesign.com.au/presentation/page_layouts/
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Clean & Sober" <[email protected]>
    wrote in message
    news:edgvl4$akl$[email protected]..
    > Hello,
    >
    > I've done table-based layouts for several years, but I'm
    trying to switch
    > to
    > CSS. I still have a lot to learn...
    >
    > I'm trying to create a web site as a favor for a friend.
    She hasn't
    > figured
    > out what she wants yet, so I've just been creating some
    pages using canned
    > designs. I created one using "Two-column left nav" under
    Dreamweaver's
    > "Page
    > designs (CSS)":
    >
    >
    http://www.alcie.org/demo2/
    >
    > I want a fixed-width left navigation column and a fluid
    content column.
    >
    > I ran into several problems with the original design.
    The most notible
    > was
    > that if I changed the browser window width, both the
    content and nav
    > columns
    > would resize. I didn't want that, so I set "navBar"
    width: 150px. That
    > worked, but if I make the window too narrow, the content
    starts to overlap
    > the
    > navigation column in Firefox 1.5.0.6, and the navigation
    DIV drops to
    > below the
    > content in IE 7 rc (I think) 3 and IE6. I tried removing
    the width
    > altogether,
    > but that made things worse.
    >
    > What is wrong with this picture? Is there a cleaner way
    to solve my
    > problem?
    >
    > Thanks.
    >

  • Two column primary keys

    Hello,
    I am using two columns for my primary key. However when I crate a report and form pages, it doesn't work. The report page shows up but when I click on the edit icon next to each record it gives an error message.

    Zahid Khan wrote:
    Hi User (very common name!),
    In the following simple page I am using empno and hiredate columns as primary key:
    http://apex.oracle.com/pls/otn/f?p=9396:10
    It would be easier to help you if you set up an example on OTN.
    Thanks,
    ZahidDear Zahid,
    I looked at the application example you provided and the way the trigger ensures the trunc function is called on the date field before writing it to the db table, so the date retrieved from the db looks exactly the same as the date inserted.
    CREATE TABLE "EMP_DATE_KEY"
    (     "EMPNO" NUMBER,
         "ENAME" VARCHAR2(10),
         "HIREDATE" DATE,
         "SAL" NUMBER,
         "DEPTNO" NUMBER,
         CONSTRAINT "PK_EMP_DATE_KEY" PRIMARY KEY ("EMPNO", "HIREDATE") ENABLE
    CREATE OR REPLACE TRIGGER "BIUD_EMP_DATE_KEYS"
    before insert on emp_date_key
    for each row
    begin
    select nvl(max(empno),0)+1, trunc(sysdate)
    into :new.empno, :new.hiredate from emp_date_key;
    end;
    ALTER TRIGGER "BIUD_EMP_DATE_KEYS" ENABLE
    Line: --------
    However the database I am dealing with has not used the trunc function when creating the date field values and the primary key, by the way this db is very old and has a lot of data in it.
    any suggestions?
    Thanks,
    user

  • Using two iPhones with one Apple id

    Hello!!
    I am currently an iPhone 3GS user.  I just got my new iPhone 5 and as I use two numbers, thought of switching my other number to this 3GS and thus using 2 iPhones for both the numbers.  So, can someone tell me if I can use the same Apple id for both the cell or I need to create a new one to use two iPhones.  (Please note: I use iCloud only for contacts sync and dont mind having same contacts on both the devices)
    Shall appreciate a quick response!
    Thank you. 

    Really appreciate this quick response.  So I guess there won't be an issue to use the same id on two iPhones at the same time.
    Thanks again!

Maybe you are looking for