Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JRootPane?

Reply
Thread Tools

JRootPane?

 
 
Knute Johnson
Guest
Posts: n/a
 
      11-06-2005
Michael Dunn wrote:
> "Knute Johnson" <(E-Mail Removed)> wrote in message
> news:ticbf.7405$(E-Mail Removed)...
>
>
>>how to get at the RootPane from inside my JPanel .

>
>
> It has to be added to the content pane before you call your getParent()'s
> I gather you have no control over this, just the Panel. Perhaps a timer
> might be one way.
>
> Something like this


Thanks very much. I shouldn't be working this late at night or I would
have figured that one out (maybe?). Your example has the one problem
though that I was worried about and that is that the button gets pressed
even if the tabbed pane that it lives on is not the current tab.

I think I'm going to give up on this route.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      11-06-2005
On Sat, 05 Nov 2005 10:53:56 -0800, Knute Johnson
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>to use JComponent.getRootPane() and
>SwingUtilities.getRootPane(JComponent) and
>getTopLevelAncestor().getRootPane() all with the same result, null.
>


JRootPane rootPane = jframe.getRootPane();

Your real problem was getting the JFrame.

GetParent iteratively with a check for JFrame instance is I guess what
you needed, or embed a back link when you added the JPanel.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      11-06-2005
On Sat, 05 Nov 2005 21:35:49 GMT, Andrew Thompson
<(E-Mail Removed)> wrote while drunk out of his mind on Watney's
said:

>?? I am astounded, I thought you would be able to laugh at that.


There is nothing in the least bit funny about insulting someone or
accusing them of illegal activity or incompetence.

Humour requires an element of surprise, a sudden revealing of a double
meaning, some element of bizarre incongruity, some clever word play...

An insult can be humorous, but an insult in and of itself is not
funny. And even humorous insults are still insults. The point of them
is ridicule. Look at all the energy that goes into humorously
lampooning political figures.

Your joke might work, however, if you accused Mother Theresa of toking
up.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Michael Dunn
Guest
Posts: n/a
 
      11-06-2005

"Knute Johnson" <(E-Mail Removed)> wrote in message
news:GAibf.7463$(E-Mail Removed)...
> Michael Dunn wrote:
>> "Knute Johnson" <(E-Mail Removed)> wrote in message
>> news:ticbf.7405$(E-Mail Removed)...


>the button gets pressed even if the tabbed pane that it lives on is not
>the current tab.


seerms to work OK doing it this way (1.5.0_03)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Testing extends JFrame
{
public Testing()
{
setSize(100,100);
setLocation(300,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JTabbedPane tp = new JTabbedPane();
TabPanel p = new TabPanel();
tp.addTab("tab 1",p);
tp.addTab("tab 2",new JPanel());
getContentPane().add(tp);
}
public static void main(String[] args){new Testing().setVisible(true);}
}
class TabPanel extends JPanel
{
JButton btn = new JButton("OK");
public TabPanel()
{
add(btn);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
buttonAction();}});
KeyboardFocusManager.getCurrentKeyboardFocusManage r()
.addKeyEventDispatcher(new KeyEventDispatcher(){
public boolean dispatchKeyEvent(KeyEvent ke){
if(TabPanel.this.isVisible() && ke.getID() ==
KeyEvent.KEY_PRESSED)
{
if(ke.getKeyCode() == KeyEvent.VK_ENTER) buttonAction();
}
return false;}});
}
public void buttonAction()
{
JOptionPane.showMessageDialog(null,"OK");
}
}


 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      11-06-2005
Michael Dunn wrote:
> "Knute Johnson" <(E-Mail Removed)> wrote in message
> news:GAibf.7463$(E-Mail Removed)...
>
>>Michael Dunn wrote:
>>
>>>"Knute Johnson" <(E-Mail Removed)> wrote in message
>>>news:ticbf.7405$(E-Mail Removed)...

>
>
>>the button gets pressed even if the tabbed pane that it lives on is not
>>the current tab.

>
>
> seerms to work OK doing it this way (1.5.0_03)
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> class Testing extends JFrame
> {
> public Testing()
> {
> setSize(100,100);
> setLocation(300,200);
> setDefaultCloseOperation(EXIT_ON_CLOSE);
> JTabbedPane tp = new JTabbedPane();
> TabPanel p = new TabPanel();
> tp.addTab("tab 1",p);
> tp.addTab("tab 2",new JPanel());
> getContentPane().add(tp);
> }
> public static void main(String[] args){new Testing().setVisible(true);}
> }
> class TabPanel extends JPanel
> {
> JButton btn = new JButton("OK");
> public TabPanel()
> {
> add(btn);
> btn.addActionListener(new ActionListener(){
> public void actionPerformed(ActionEvent ae){
> buttonAction();}});
> KeyboardFocusManager.getCurrentKeyboardFocusManage r()
> .addKeyEventDispatcher(new KeyEventDispatcher(){
> public boolean dispatchKeyEvent(KeyEvent ke){
> if(TabPanel.this.isVisible() && ke.getID() ==
> KeyEvent.KEY_PRESSED)
> {
> if(ke.getKeyCode() == KeyEvent.VK_ENTER) buttonAction();
> }
> return false;}});
> }
> public void buttonAction()
> {
> JOptionPane.showMessageDialog(null,"OK");
> }
> }
>
>


That's a not a bad idea Michael, I just might use that one.

Thanks,

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments