Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33470

Re: Swing - Using JTabbedPane

Newsgroups comp.lang.java.programmer
Date 2016-01-18 06:39 -0800
References <df13f200-8551-4401-9da0-ad0ecc203a5e@googlegroups.com>
Message-ID <9ceacb33-c920-4100-9fae-5268bdc09d7e@googlegroups.com> (permalink)
Subject Re: Swing - Using JTabbedPane
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


On Saturday, January 16, 2016 at 10:54:12 AM UTC-5, gal...@hotmail.com wrote:
> So I'm throwing JTables into JScrollPanes and then adding them as 
> new tabs, but when I want to read the selected table again later, I'm 
> not sure what to do. Right now the code below seems to be working, 
> but I'm not sure if it is a good approach. Also JViewport is a mystery.
> 
> 
> int tab = jTabbedPane1.getSelectedIndex();
>         
> if (tab == -1){
>    statusMessageLabel.setText("Error: no tab is selected."); 
>    return;
> }
>         
> Component csp = jTabbedPane1.getComponent(0);
> Component cvp;
> Component cjt;
>         
> JTable jt = null;
>         
> if (csp instanceof JScrollPane){
>    cvp = ((JScrollPane)csp).getComponent(0);
>    if (cvp instanceof JViewport){
>        cjt = ((JViewport)cvp).getComponent(0);
>        if (cjt instanceof JTable){
>            jt = (JTable)cjt;
>        }
>    }
> }
>         
> if (jt == null){
>     statusMessageLabel.setText("Error: selected tab "+ tab + " is not a table.");
>     return;
> }

If you have a more complete example code you can get a more complete answer.

I rarely get a component I created from another component.  Normally I keep a pointer to the component for future reference.

I create all tables as a custom class which extends JTable, which adds the table by default to a JScrollPane in the constructor, because why would you need a JTable without a scroll pane?

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Swing - Using JTabbedPane galt_57@hotmail.com - 2016-01-16 07:53 -0800
  Re: Swing - Using JTabbedPane Jeff Higgins <jeff@invalid.invalid> - 2016-01-16 19:29 +0000
    Re: Swing - Using JTabbedPane galt_57@hotmail.com - 2016-01-17 06:35 -0800
      Re: Swing - Using JTabbedPane Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-01-17 10:08 -0500
      Re: Swing - Using JTabbedPane Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-01-17 09:49 -0800
        Re: Swing - Using JTabbedPane Martin Gregorie <martin@address-in-sig.invalid> - 2016-01-17 20:00 +0000
  Re: Swing - Using JTabbedPane Jeff Higgins <jeff@invalid.invalid> - 2016-01-17 14:21 +0000
  Re: Swing - Using JTabbedPane Eric Douglas <e.d.programmer@gmail.com> - 2016-01-18 06:39 -0800

csiph-web