Help coderanch get a
new server
by contributing to the fundraiser
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

warning mesage before leaving particular tab in swings

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,


I have a tabbed pane,its having differenet tabs,
I wanted to display some message on console before leaving particular tab.

With example the following example the message is displaying while leaving any of the tab,but i wanted to dsplay the message only when i am leaving from TAB A.

import java.awt.BorderLayout;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.*;
public class tabbedPane implements FocusListener {
public static void main(String args[]) throws Exception {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
String titles[] = { "A", "B", "C", "D", "E", "F" };
int mnemonic[] = { KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C, KeyEvent.VK_D, KeyEvent.VK_E,
KeyEvent.VK_F };
for (int i = 0, n = titles.length; i < n; i++) {
add(tabbedPane, titles[i], mnemonic[i]);
}

ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent changeEvent) {
JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
int index = sourceTabbedPane.getSelectedIndex();

if((!sourceTabbedPane.getTitleAt(index).equals("A")))
{
System.out.println("tab changed from a");
}

}
};
tabbedPane.addChangeListener(changeListener);

frame.add(tabbedPane, BorderLayout.CENTER);
frame.setSize(400, 150);
frame.setVisible(true);

}

static void add(JTabbedPane tabbedPane, String label, int mnemonic) {
int count = tabbedPane.getTabCount();
JButton button = new JButton(label);
tabbedPane.addTab(label, button);
tabbedPane.setMnemonicAt(count, mnemonic);

}
}

Thanks in advance...
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please use code tags while you post any code. As far as you code is concerned you need a small logical change in the code, i.e you need to know whether the previous clicked tab was A or not.



 
sireesha Makkapati
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks for your reply..
Have a Nice Day.
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
...
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Mahesh,
I am sorry but I had to edit our your post as you were hijacking someone else's thread.
http://faq.javaranch.com/java/UseOneThreadPerQuestion

You can post your question by starting a new thread.
 
    Bookmark Topic Watch Topic
  • New Topic