JTabbedPane,JTable in JPopupMenu

Hai,
In my applet, I have added JTabbedPane and JTable in JPopupmenu just like JPanel using Java 1.3. It works fine. Now when I run this applet using Java 1.5 plugin, if I click on that JTable or JTabbedPane over JPopupmenu it closed automatically. It works fine in Java 1.4 also.
Any ideas...?

Hai,
Finally I got solution for this. If I use
show(Component invoker, int x, int y) method it gives problem. So
I have changed my code using setLocation(int x,int x) and then
setVisible(true). It works fine.
But Now I have got another problem. If I add JTextField over JPopupMenu, I couldn't edit that textfield.
Anybody having solution for this?

Similar Messages

  • JTable And JPopupMenu

    Hello, In a JTable i want when the user press the right button of the mouse to chose an action on JPopupMenu it automaticly select the row where the Press The Right Button.

    In your MouseListener you use table.getRowAtPoint(...) to get the row, then you can use table.setRowSelectionInverval(...) to select the row.

  • Jtable in Jpopupmenu

    is it posoble to put a table in a jpopupmenu?

    no.well, it is possible, but...
    why on earth would one want to do a thing like this!exactly....
    Actually, in 1.5, support for any components other than MenuElement implementations is broken - at least with regard to mouse events, which is pretty important. But in 1.4, I believe this would work fine.

  • Java Package/Class Dependency

    Hi, friends,
    I would like to get a list of packages that a given package depends on. If it is possible, I would also know which class of the given package depends on which classes.
    Is there any software to do this?
    If I would like to write a Java utility for that purpose, how can I proceed?
    Best regards,
    Youbin

    in the HTML fles of the java doc, you can know the class hierarchy and antecedents of each class. For example, class JComponent :
    java.lang.Object
    |
    --java.awt.Component
    |
    --java.awt.Container
    |
    --javax.swing.JComponent
    Moreover, the java doc also show the inner classes, fields and methods inherited from those super classes...
    you may also know which classes extends this one. For example JComponent :
    All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable
    Direct Known Subclasses:
    AbstractButton, BasicInternalFrameTitlePane, Box, Box.Filler, JColorChooser,
    JComboBox, JFileChooser, JInternalFrame, JInternalFrame.JDesktopIcon, JLabel,
    JLayeredPane, JList, JMenuBar, JOptionPane, JPanel, JPopupMenu, JProgressBar,
    JRootPane, JScrollBar, JScrollPane, JSeparator, JSlider, JSpinner, JSplitPane,
    JTabbedPane, JTable, JTableHeader, JTextComponent, JToolBar, JToolTip, JTree,
    JViewport
    vincent

  • Converting Swing to Applets

    Hello
    I have a swing GUI and my employer asked me to convert the whole thing into applets. I just wonder if there is a simpler way of doing it. My GUI now contains only basic swing components like JTabbedPane, JTable etc...,
    Thanks.

    There may also be resource and security issues associated with the conversion. On the whole modifying the entry point is fairly simple ... convert to JApplet, make sure you have an init method to replace the main method as your entry point. You will need HTML to start the applet.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Resize JTable in JTabbedPane

    Given the FileTableDemo from the Java Foundation Class in a Nutshell book.(O'Reilly) Chapter 3 page 51 in my addition.
    I have modified the example to place the JTable in a JTabbedPane. Now when the window (JFrame) is resized by the user the JTable no longer resizes. How do I passing the "resizing" into the component (JTable) placed in the JTabbedPane?
    Here is the code: My deviation from the example is enclosed in "///////////KBS" and of course the line frame.getContentPane().add(myTP, "Center"); where "pane" has been replaced with "myTP"
    Thanks Brad
    import javax.swing.*;
    import javax.swing.table.*;
    import java.io.File;
    import java.util.Date;
    public class FileTableDemo
    public static void main(String[] args)
    // Figure out what directory to display
    File dir;
    if (args.length > 0)
    dir = new File(args[0]);
    else
    dir = new File(System.getProperty("user.home"));
    // Create a TableModel object to represent the contents of the directory
    FileTableModel model = new FileTableModel(dir);
    // Create a JTable and tell it to display our model
    JTable table = new JTable(model);
    JScrollPane pane = new JScrollPane(table);
    pane.setBorder(BorderFactory.createEmptyBorder(60,20,20,20));
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    JPanel myOne = new JPanel();
    JPanel myTwo = new JPanel();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS
    // Display it all in a scrolling window and make the window appear
    JFrame frame = new JFrame("FileTableDemo");
    frame.getContentPane().add(myTP, "Center");
    frame.setSize(600, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    // The methods in this class allow the JTable component to get
    // and display data about the files in a specified directory.
    // It represents a table with six columns: filename, size, modification date,
    // plus three columns for flags: direcotry, readable, writable
    class FileTableModel extends AbstractTableModel
    protected File dir;
    protected String[] filenames;
    protected String[] columnNames = new String[] {
    "name",
    "size",
    "last modified",
    "directory?",
    "readable?",
    "writable?"
    protected Class[] columnClasses = new Class[] {
    String.class,
    Long.class,
    Date.class,
    Boolean.class,
    Boolean.class,
    Boolean.class
    // This table model works for any one given directory
    public FileTableModel(File dir)
    this.dir = dir;
    this.filenames = dir.list();
    // These are easy methods
    public int getColumnCount()
    return 6;
    public int getRowCount()
    return filenames.length;
    // Information about each column
    public String getColumnName(int col)
    return columnNames[col];
    public Class getColumnClass(int col)
    return columnClasses[col];
    // The method that must actually return the value of each cell
    public Object getValueAt(int row, int col)
    File f = new File(dir, filenames[row]);
    switch(col)
    case 0: return filenames[row];
    case 1: return new Long(f.length());
    case 2: return new Date(f.lastModified());
    case 3: return f.isDirectory() ? Boolean.TRUE : Boolean.FALSE;
    case 4: return f.canRead() ? Boolean.TRUE : Boolean.FALSE;
    case 5: return f.canWrite() ? Boolean.TRUE : Boolean.FALSE;
    default: return null;
    }

    Well, I didn't find an answer but I did find a solution.
    The JPanel is the problem. I use it to help with layout which is not obvious in this example.
    As you can see in the code the JTable is placed in a JScrollPane which is place in a JPanel which is placed in a JTabbedPane.
    If I use Box instead of JPanel the JTable in the JScrollPane in the Box in the TabbedPane in the JFrame resizes correclty.
    So although JPanel is resizable with setSize it does not get resized when it's JFrame gets resized.
    I would still like to know why?
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    Box myOne = Box.createHorizontalBox();
    Box myTwo = Box.createHorizontalBox();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS

  • Issue with re-sizing JTable Headers, JTabbedPane and JSplit pane

    Ok, hopefully I'll explain this well enough.
    In my Swing application I have a split pane, on the left hand side is a JTable and on the right hand is a JTabbedPane. In the tabs of the JTabbedPane there are other JTables.
    In order to make the rows in the JTable on the left and the JTable(s) on the right line up, the Table Header of all the tables is set to the size of the tallest (deepest?) table header.
    Hopefully so far I'm making sense. Now to get to the issue. One of the tables has a number of columns equal to the value on a NumberSpinner (it represents a number of weeks). When this value is changed the table is modified so that it contains the correct number of columns. As the table is re-drawn the table header goes back to its default size so I call my header-resize method to ensure it lines up.
    The problem is this: if I change the number of weeks when selecting a tab other than the one containing my table then everything is fine, the table header is re-sized and everything lines up. If I change the number of weeks with the tab containing the table selected, the column headers stay at their standard size and nothing lines up.
    To make things more complicated, I also put System.out.println's in as every method called in the process to obtain the size of the table header. And every println returned the same height, the height the table header should be.. So I'm really confused.
    Could anyone shed any light on this?
    Thanks.

    Okay I managed to solve the problem by explicitly revalidating and repainting the table header.
    Not sure why it wasnt doing it properly for that table when all the others where fine.
    Oh well...

  • JTable in JPanel in JTabbedPane in JScrollPane in JSplitPane problem

    I have a JSplitPane with a divider in the center; of which the top is a JPanel and the bottom is a JScrollPane that contains a JTabbedPane, for which each tab contains a JPanel which contains a JTable.
    When I move the divider up, so that it now takes up 75% of the JSplitPane, the JScrollPane and the JTabbedPane expand with the JSplitPane, but the JPanel that contains the JTable remains the same size that it had at the beginning.
    What I would like to see is more rows of the JTable as I move the divider to give the JScrollPane more room.
    Is there an easy way to keep all of the J components sizes in sync as the JSplitPane gets larger or smaller ? (JDK 1.3.1)

    Hi,
    The JPanels which you have inside each tab of the JTabbedPanes should have BorderLayout and the JScrollPanes which hold the JTables should be added with the BorderLayout.CENTER constraint. This will make sure that the JScrollPanes that contain the JTables occupy as much space as possible.
    Hope this helps,
    Ranga.

  • JTable in JTabbedPane

    Hello
    I have a little GUI problem. I created a dialog with a JTabbedPane in the center that contains some JPanel with labels, fields etc. (nothing heavy). The Dialog has a size about 100px*200px.
    Now I put a JTable (with no sizing information) in a JScrollPane and add it to the JTabbedPane and the Dialog gets a size of about 200px*200px.
    Why? I tried a lot, but nothing helped?
    Thankful for every help.

    Oh sorry,
    I want that the JTable (and the JScrollPane) adopts the size of the Dialog (before I added the table). I don't set any size in my code for the dialog and the panels. I set only size for some JFields in the panels and pack() the dialog.
    First everything is wonderfull aligned, but when I add the scrollpane with the table the whole dialog becomes wider.
    Is there a chance that the new tab gets the old size?

  • Ctrl PgUp / CtrlPgDown in JTables vs JTabbedPanes

    Hi there, another wee JTable problem.
    I want Ctrl PageUp and Ctrl PageDown to move between JTabbedPanes. This normally works, except when the focus is currently in a JTable. I want it to also work if the focus is in a JTable.
    I have tried to stop the JTable from handling the keys by setting the inputmap to "none" but this has no effect (you can see my code for this below).
    Here is a test program that shows the bad behaviourimport java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.InputMap;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.KeyStroke;
    public class TestTable extends JTable {
         public TestTable(Object[][] data, Object[] headings) {
              super(data, headings);
              setFocusTraversalPolicyProvider(true);
              // Turn off Ctrl PgUp and Ctrl PgDown handling so tab navigation works.
              InputMap inputs = getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
              KeyStroke ctrlPgUpKey = KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_DOWN_MASK);
              inputs.put(ctrlPgUpKey, "None");
              KeyStroke ctrlPgDownKey = KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, InputEvent.CTRL_DOWN_MASK);
              inputs.put(ctrlPgDownKey, "None");
         public boolean isCellEditable(int row, int column) {
              return false;
         public static void main(String[] args) {
              JFrame frame = new JFrame("Test table");
              JTabbedPane pane = new JTabbedPane();
              frame.add(pane);
              JPanel panel = new JPanel();
              JTextField field = new JTextField("Key Ctrl PgDown or Ctrl PgUp");
              panel.add(field);
              pane.add("test1", panel);
              pane.add("test2", new JScrollPane(new TestTable(new String[][] {{"hello", "me"}}, new String[]{"H1", "H2"})));
              pane.add("test3", new JPanel());
              frame.setBounds(100, 100, 300, 300);
              frame.setVisible(true);
    }Thanks,
    Tim

    i had a similiar problem, had some UIs that had a Tabbed pane and
    ScrollBars, and some tabs had JTables in them, anyhow, I just wanted
    Control-Page_up/Down to work for the JTabbedPane all the the time so
    I did this in my windows look and feel applications and all was well, just posting so maybe this will help someone down the road
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    UIDefaults uiDefaults = UIManager.getDefaults();
    // ginny wants Control-Page-Up and Control-Page-Down to work for tabbed
    // panes, which it does by default, however, it also works for JTable
    // and JScrollPane, and those components grab the keystroke 1st if they are
    // all in the same screen, so disabling it for JTable and JScrollPane
    // see WindowsLookAndFeel.java
    uiDefaults.remove("ScrollPane.ancestorInputMap");
    uiDefaults.put("ScrollPane.ancestorInputMap",
    new UIDefaults.LazyInputMap(new Object[] {
    "RIGHT", "unitScrollRight",
    "KP_RIGHT", "unitScrollRight",
    "DOWN", "unitScrollDown",
    "KP_DOWN", "unitScrollDown",
    "LEFT", "unitScrollLeft",
    "KP_LEFT", "unitScrollLeft",
    "UP", "unitScrollUp",
    "KP_UP", "unitScrollUp",
    "PAGE_UP", "scrollUp",
    "PAGE_DOWN", "scrollDown",
    "ctrl PAGE_UP", "None", //"scrollLeft",
    "ctrl PAGE_DOWN", "None",//"scrollRight",
    "ctrl HOME", "scrollHome",
    "ctrl END", "scrollEnd"
    uiDefaults.remove("Table.ancestorInputMap");
    uiDefaults.put("Table.ancestorInputMap",
    new UIDefaults.LazyInputMap(new Object[] {
    "ctrl C", "copy",
    "ctrl V", "paste",
    "ctrl X", "cut",
    "COPY", "copy",
    "PASTE", "paste",
    "CUT", "cut",
    "RIGHT", "selectNextColumn",
    "KP_RIGHT", "selectNextColumn",
    "LEFT", "selectPreviousColumn",
    "KP_LEFT", "selectPreviousColumn",
    "DOWN", "selectNextRow",
    "KP_DOWN", "selectNextRow",
    "UP", "selectPreviousRow",
    "KP_UP", "selectPreviousRow",
    "shift RIGHT", "selectNextColumnExtendSelection",
    "shift KP_RIGHT", "selectNextColumnExtendSelection",
    "shift LEFT", "selectPreviousColumnExtendSelection",
    "shift KP_LEFT", "selectPreviousColumnExtendSelection",
    "shift DOWN", "selectNextRowExtendSelection",
    "shift KP_DOWN", "selectNextRowExtendSelection",
    "shift UP", "selectPreviousRowExtendSelection",
    "shift KP_UP", "selectPreviousRowExtendSelection",
    "PAGE_UP", "scrollUpChangeSelection",
    "PAGE_DOWN", "scrollDownChangeSelection",
    "HOME", "selectFirstColumn",
    "END", "selectLastColumn",
    "shift PAGE_UP", "scrollUpExtendSelection",
    "shift PAGE_DOWN", "scrollDownExtendSelection",
    "shift HOME", "selectFirstColumnExtendSelection",
    "shift END", "selectLastColumnExtendSelection",
    "ctrl PAGE_UP", "None", //"scrollLeftChangeSelection",
    "ctrl PAGE_DOWN", "None", //"scrollRightChangeSelection",
    "ctrl HOME", "selectFirstRow",
    "ctrl END", "selectLastRow",
    "ctrl shift PAGE_UP", "scrollRightExtendSelection",
    "ctrl shift PAGE_DOWN", "scrollLeftExtendSelection",
    "ctrl shift HOME", "selectFirstRowExtendSelection",
    "ctrl shift END", "selectLastRowExtendSelection",
    "TAB", "selectNextColumnCell",
    "shift TAB", "selectPreviousColumnCell",
    "ENTER", "selectNextRowCell",
    "shift ENTER", "selectPreviousRowCell",
    "ctrl A", "selectAll",
    "ESCAPE", "cancel",
    "F2", "startEditing"
    }));

  • JTabbedPane modifying a JTable

    Can a JTabbedPane change the internal layout of a component ?.
    I have a pane with some labels and a JTable inside with a layout. It looks fine when setting it as the content pane of a frame, but when I add it to a JtabbedPane in a new tab the JTable looks wrong.
    I am using a TableLayout, i don't know if it has something todo with the problem.
    Any idea what i'm doing wrong ?

    Any idea what i'm doing wrong ? Absolutely none.
    How to create a [url http://www.physci.org/codes/sscce.jsp]Short, Self Contained, Correct (Compilable), Example

  • JTable on JTabbedPane

    Hi,
    I was wondering how you would add a JTable onto a JTabbedPane?
    Thanks

    import javax.swing.*;
    import java.awt.*;
    public class TabTable {
         TabTable(){
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame f = new JFrame("JTable in JTabbedPane ...");
              JTabbedPane tab = new JTabbedPane();
              Object table [][] = {{"Singaravelan","21","MALE"},{"Devanderan","19","MALE"}};
              String column [] = {"NAME","AGE","SEX"};
              JTable jtable = new JTable(table,column);
              JPanel panel = new JPanel();
              panel.setLayout(new FlowLayout());
              panel.add(jtable);
              tab.addTab("Table 1",panel);
              tab.addTab("Table 2",new JLabel("Table 2",JLabel.CENTER));
              tab.addTab("Table 3",new JLabel("Table 3",JLabel.CENTER));
              f.getContentPane().add(tab);
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.setSize(500,500);
              f.setVisible(true);
         public static void main(String args[]){
              new TabTable();          
    }

  • Adding JPopupMenu to JTable cell

    Hi,
    I am just wondering if I can add a JPopup menu to each cell in a JTable, so that a user can perform some tasks.For example , a user should be able to delete a table cell by choosing the delete menu item in the popup menu
    many thanks
    Ramesh

    Hi,
    Add JPopupmenu and add JMenuItems on that according to your requirement. Add MouseListener to your table and on mouseReleased event check whether you have clicked the right mouse. If right mouse is clicked, then show the popup menu that you have already created. I think the following code will help you.
    JPopupMenu lJPopupMenu = new JPopupMenu();
    JMenuItem lJMenuItem1 = new lJMenuItem();
    lJPopupMenu.add(lJMenuItem1);
    lJTable.addMouseListener(this);
    MouseReleased(java.awt.event.MouseEvent mouseEvent) {
    if(mouseEvent.isPopupTrigger()){
    lJPopupMenu.show(lJTable, mouseEvent.getX(), mouseEvent.getY());
    ActionPerformed of the JMenuItem, you write the code based on the requirement.

  • Add a jpopupmenu to a jtabbedpane

    hi guys,
    i want to add a popupmenu to each tab in a jtabbedpane. i dont know how to implement it so i ask here.
    it just shall have a close-menuitem.
    does someone know how to solve that? please help!

    Hello,
    I have a test I've made long ago. It works.
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.JTabbedPane;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.*;
    import java.awt.event.*;
    public class TabbedPaneDemo extends JPanel {
        public TabbedPaneDemo() {
            JTabbedPane tabbedPane = new JTabbedPane();
              addListenerToPane(tabbedPane);
            Component panel1 = makeTextPanel("Blah");
            tabbedPane.addTab("One", null, panel1, "Does nothing");
            tabbedPane.setSelectedIndex(0);
            Component panel2 = makeTextPanel("Blah blah");
            tabbedPane.addTab("Two", null, panel2, "Does twice as much nothing");
            Component panel3 = makeTextPanel("Blah blah blah");
            tabbedPane.addTab("Three", null, panel3, "Still does nothing");
            Component panel4 = makeTextPanel("Blah blah blah blah");       
            tabbedPane.addTab("Four", null, panel4, "Does nothing at all");
            //Add the tabbed pane to this panel.
            setLayout(new GridLayout(1, 1));
            add(tabbedPane);
         private void addListenerToPane(final JTabbedPane tabbed)
              tabbed.addMouseListener(new MouseAdapter() {
                                  public void mousePressed(MouseEvent me)
                                       maybeShowPopup(me);
                                  public void mouseReleased(MouseEvent me)
                                       maybeShowPopup(me);
        protected Component makeTextPanel(String text) {
            JPanel panel = new JPanel(false);
            JLabel filler = new JLabel(text);
            filler.setHorizontalAlignment(JLabel.CENTER);
            panel.setLayout(new GridLayout(1, 1));
            panel.add(filler);
            return panel;
        public static void main(String[] args) {
            JFrame frame = new JFrame("TabbedPaneDemo");
            frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {System.exit(0);}
            frame.getContentPane().add(new TabbedPaneDemo(),
                                       BorderLayout.CENTER);
            frame.setSize(400, 125);
            frame.setVisible(true);
         private void maybeShowPopup(final MouseEvent me)
              if (me.isPopupTrigger()) {
                   JPopupMenu popup = new JPopupMenu();
                   JMenuItem item = new JMenuItem("Close");
                   popup.add(item);
                   item.addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent e)
                                  JTabbedPane tabbed = (JTabbedPane)me.getSource();
                                  int i = tabbed.getSelectedIndex();
                                  tabbed.remove(i);
                   popup.show(me.getComponent(), me.getX(), me.getY());
    }

  • JTable and JTabbedPane questions

    I have an application which has some JTabbedPanes setup, one of which has a table on it.
    What i'm after is a way of having a user select a row from the table and in doing so this will send them to another tabbedpane.
    So what i need is a way of assigning each row an ID number, then being able to extract this ID, and being able to switch to a new tab without having to click on the tab itself.
    I hope someone can point me in the right direction.
    One more question as well.
    I'm designing a networked bulletinboard application (using javaspaces) and i'm having an implementation issue.
    At the moment I can list all the topics in a table which just contains |the author, topic title and date created|.
    I'm having trouble thinking of a good way of displaying the actuall topic itself (and multiple follow-up posts).
    I was thinking of doing this in another table, but i couldnt find a way of customizing the layout enough to display formatted text. So i thought I would just do a loop of JTextAreas for each topic.
    Something along the lines of:
    while (i < number_of_posts)
    Create_JTextArea(post[i]);
    Do you think this would be a suitable way of implementing this? Or is there a better way that i'm missing?

    So what i need is a way of assigning each row an ID numberStore the ID number in the TableModel. You then just remove the TableColumn from the TableColumnModel and the ID will not be displayed in the table. You then simply use model.getValueAt(...) to reference the ID.

Maybe you are looking for

  • Adding Images in the Interactive Form

    Dear All,     How to add a image in the standard SAP Deliver interactive forms for the PCR. Can i able to change the logo which is available in the system to the custom logo. So that will it get reflected in the all the standard screen using the logo

  • Should it work with screen removed and monitor connected?

    My screen died, the machine is ageing so I thought -just remove the screen and plug in a monitor I know works - and use as a desktop. Removing the screen was OK - but the machine will now not switch on. Have I done something silly or does the screen

  • Color correcting w/ Effects tab......

    I've applied the color correction from the Effects tabl under video filter to a particular clip in a particular sequence. And, I'm attempting to simply start the clip at zero saturation and then end the clip at 100 saturation. I've set key frame poin

  • Retreiving HTML data from an URL

    It is possible to get HTML data (HTML source) from Java (text), and store them in a string ? Using java application (no gui).

  • Add a button in javabean class

    hi how can i have an add button in my class, i what an action listener in my class which will allow me to have a button to add a record in my javabean,i what to have createInsert button,how can i create that in my class.am not yet connect to database