Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33468
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Swing - Using JTabbedPane |
| Date | 2016-01-17 09:49 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <n7gk2k$9qi$1@dont-email.me> (permalink) |
| References | <df13f200-8551-4401-9da0-ad0ecc203a5e@googlegroups.com> <n7e5m2$ojp$1@dont-email.me> <78ecf434-7366-4dd4-a083-7319f78aad4c@googlegroups.com> |
On 1/17/2016 06:35, galt_57@hotmail.com wrote:
> On Saturday, January 16, 2016 at 1:32:07 PM UTC-6, Jeff Higgins wrote:
>> On Sat, 16 Jan 2016 07:53:54 -0800, galt_57 wrote:
>>
>>> So I'm throwing JTables into JScrollPanes and then adding them as new
>>> tabs,
>>
>> You've not shown any of this code.
>>
>>> but when I want to read the selected table again later, I'm not
>>> sure what to do.
>>
>> Here are some resources to help you figure it out.
>>
>> Java SE API Documentation
>> https://docs.oracle.com/javase/8/docs/api/index.html
>>
>> The Java(tm) Tutorials - Creating a GUI with Swing
>> https://docs.oracle.com/javase/tutorial/uiswing/index.html
>>
>>> Right now the code below seems to be working,
>>
>> Great!
>>
>>> but I'm not sure if it is a good approach.
>>
>> Impossible to tell without the rest of the code.
>>
>>> Also JViewport is a mystery.
>>
>> See the above resources.
>>
>
> Thanks for the references.
>
> Let me post a correction to my original code and add a summary of how I create the tab...
>
> JTable jt;
> DefaultTableModel mod;
> .
> . //fill the table body
> .
> JScrollPane sp = new JScrollPane(jt);
> jTabbedPane01.addTab(tabname,sp); // so here the tab has been created
>
> ----------------
>
> // in the routine below I want to read the jtable in the selected tab...
>
> int tab = jTabbedPane01.getSelectedIndex();
>
> if (tab == -1){
> statusMessageLabel.setText("Error: no tab selected.");
> return;
> }
>
> Component csp = jTabbedPane01.getComponentAt(tab);
> 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;
> }
>
This seems like a lot of work to find your JTables when you could just
keep a list of references to them somewhere. That way, you wouldn't
care what your component hierarchy was and you could change it without
having to rewrite your code.
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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