Test frames

I am setting up the frames for the first time on this network and want to make sure that they are working from end to end.  I did in the past with windows by running 'ping < storage_proc_IP > f-l 9000', so I thought that the same type of thing could work in mode not supported for ESXi 4.1.

After you have configured the frames extended on the vmknics, vSwitch, physical switches and storage system, I SSH into my box of ESXi 4.1 and ran 'vmkping < storage_proc_IP > s 9000' and get this answer "9008 bytes of < storage_proc_IP >: icmp_seq = 0 ttl = 255 time = 0.648 ms."  So you it seems that it worked right?

Well well... being the ever skeptical person I am I then ran this command "vmkping < storage_proc_IP > s 65000" and get this answer "65008 bytes of < storage_proc_IP >: icmp_seq = 0 ttl = 255 time = 1.782 ms."

So, naturally, I searched a fragment anti pass as windows a - f, but I couldn't find one.

Can someone point me in the right direction as to how I should test with ESXi jumbo frames?

Use the option-d (on IPv4 packets DF bit set)

Tags: VMware

Similar Questions

  • The best way to manage two GUI

    I have two classes using java swings. The first Panel is where all the calculations will be made and the result will appear in a JList (in the 1st Panel). After that, the next button will show a 2nd Panel where the JList of the 1st group results are transferred. I need a back button in the 2nd Panel to return to the Panel 1. After you click the back button, I need the previous results on the 1st Panel to always be there for extra change (add / change / delete data). If I changed something and click the next button again, I want the 2nd Panel show a set results to date from the 1st Panel.

    What is the best way to do it? I spent two days trying to apply this using the presentation of the card, but it does not work as I want. All the examples I found use only one category. Even if I break down for separate classes, I face problem where when I click the back button, all the data in the 1st Panel disappeared. I'm out of my mind right now. It would be great if anyone can share some ideas in this. Any suggestions are welcome.

    Yes. I already tried several times to break it down into categories before posting here again. I am new to Java, that's why I found quite difficult and decided to post my problem here after he tried for two days. In any case, I thought about it already. I share the codes so that anyone who has problems like me can be useful if not much.

    Presentation of the main card:

    import java.awt.CardLayout;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public class CardCard {
      private static final String FIRST_PANEL = "firstPanel";
      public static JPanel mainPanel;
      private JFrame frame;
      public static CardPanel_1 cp1 = null;
      public static final CardLayout cardLayout = new CardLayout();
    
      public CardCard (){
      frame = new JFrame("Test");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLocationByPlatform(true);
      mainPanel = new JPanel(cardLayout);
      cp1 = new CardPanel_1();
      mainPanel.add(cp1, FIRST_PANEL);
      frame.getContentPane().add(mainPanel);
      frame.pack();
      frame.setVisible(true);
      }
    
      public static void main(String... args) {
      SwingUtilities.invokeLater(new Runnable()
      {
      public void run()
      {
      new CardCard();
      }
      });
      }
    
    }
    

    First card:

    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Observable;
    import java.util.Random;
    
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class CardPanel_1 extends JPanel {
      public static JTextField textField, textField3;
      private static final String SECOND_PANEL = "secondPanel";
      private CardPanel_2 observer;
      private JButton btnNext, btnRandom;
      private String show;
      public CardPanel_2 cp2 = null;
      private List numList;
      private String numResult;
    
      /**
      * Create the panel.
      */
      public CardPanel_1() {
      setLayout(new FlowLayout());
    
      textField = new JTextField();
      textField.setBounds(64, 5, 134, 28);
      add(textField);
      textField.setColumns(10);
    
      textField3 = new JTextField();
      textField3.setBounds(64, 5, 134, 28);
      add(textField3);
      textField3.setColumns(10);
    
      btnRandom = new JButton("Randomise");
      btnRandom.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      String str = textField.getText();
      int num = Integer.parseInt(str);
      numList = new ArrayList();
      for (int i =0;i
    

    2nd map:

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Observable;
    import java.util.Observer;
    
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class CardPanel_2 extends JPanel implements Observer {
     private static JTextField textField2;
      private JButton btnBack;
     private static final String FIRST_PANEL = "firstPanel";
    
     /**
      * Create the panel.
      */
      public CardPanel_2() {
      System.out.println("PANEL 2");
      textField2 = new JTextField();
      add(textField2);
      textField2.setColumns(10);
      btnBack = new JButton("Back");
      btnBack.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      CardCard.cardLayout.show(CardCard.mainPanel, FIRST_PANEL);
      System.out.println("BACK");
      }
      });
      add(btnBack);
      }
    
      public void update(Observable o, Object arg) {
      System.out.println("Updated: " + CardCard.cp1.textField3.getText());
      textField2.setText(CardCard.cp1.textField3.getText());
      }
    }
    
  • Why my site shake when you hover over the menu?

    My website, www.boulevardrental.com shakes when I drive on the menu buttons. I just updated to Muse and used a different font. Is there a setting that I messed up?

    The top row menus change size when reversed.

    I guess your menu item boxes are not large enough to contain the increase in text, so the frame pushes and pushes other content below down. Watch out for that the dashed lines in a test frame. It indicates the height that you defined, while the framework must actually more space.

  • Make a (get) component without pack()

    Hello

    I'm trying to implement Re: JTable column header to span several columns for a covering table header. In this example, scrollPane header is defined AFTER the framework was achieved with pack().
    In my application, however, I have several different tables that I showed a common dialog, which I pass the corresponding array containing only scrollPane. Is there a way to get the scrollPane realized before be displayed? Currently, I met a NullPointerException (to the arrow "->"). I tried doLayout() and validate() nothing helps.
    import java.awt.*;
    import java.util.Collections;
    import java.util.Enumeration;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.TableColumnModelEvent;
    import javax.swing.event.TableColumnModelListener;
    import javax.swing.table.*;
     
    public class MultiSpanHeader1 {
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
    
             @Override
             public void run() {
                new MultiSpanHeader1().makeUI();
             }
          });
       }
     
       public void makeUI() {
          final JFrame frame = new JFrame("MultiSpanHeader test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 200);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
          MyTable myTable= new MyTable();
          JScrollPane scroll= new JScrollPane(myTable);
          JPanel panel = new JPanel(new GridLayout(2, 1));
          panel.add(myTable.dummyHeader);
          panel.add(myTable.getTableHeader());
    // -->
          System.out.println(scroll.getColumnHeader()); // null
          scroll.getColumnHeader().setView(panel); // NPE
          new TableDialog(frame, scroll);
       }
    
    
       class TableDialog extends JDialog {
         public TableDialog(Frame parent, JScrollPane scroll) {
           super(parent, true);
           setLocationRelativeTo(parent);
           add(scroll);
           setVisible(true);
         }
       }
    
    
      class MyTable extends JTable {
        final JTableHeader dummyHeader;
    
        public MyTable() {
          super(5, 6);
          getTableHeader().setReorderingAllowed(false);
          final TableColumnModel model = getColumnModel();
          Enumeration<TableColumn> enumColumns = model.getColumns();
          final List<TableColumn> columns = Collections.list(enumColumns);
          
          final JTable dummy = new JTable(0, 3);
          dummyHeader= dummy.getTableHeader();
          dummyHeader.setReorderingAllowed(false);
          dummyHeader.setResizingAllowed(false);
          final TableColumnModel dummyModel = dummy.getColumnModel();
          Enumeration<TableColumn> enumDummyColumns = dummyModel.getColumns();
          final List<TableColumn> dummyColumns = Collections.list(enumDummyColumns);
          
          model.addColumnModelListener(new TableColumnModelListener() {
             @Override
             public void columnAdded(TableColumnModelEvent e) {
             }
     
             @Override
             public void columnRemoved(TableColumnModelEvent e) {
             }
     
             @Override
             public void columnMoved(TableColumnModelEvent e) {
             }
     
             @Override
             public void columnMarginChanged(ChangeEvent e) {
                dummyColumns.get(0).setWidth(columns.get(0).getWidth());
                dummyColumns.get(1).setWidth(columns.get(1).getWidth() +
                      columns.get(2).getWidth());
                dummyColumns.get(2).setWidth(columns.get(3).getWidth() +
                      columns.get(4).getWidth() + columns.get(5).getWidth());
             }
     
             @Override
             public void columnSelectionChanged(ListSelectionEvent e) {
             }
          });
        }
      }
    
    }

    You will need to substitute JTable #configureEnclosingScrollPane () to do nothing and use get #setColumnHeaderView what auto creates the window:

    import java.awt.EventQueue;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    
    public class TestTable5 {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    JTable table = new JTable(5, 5) {
                        @Override
                        protected void configureEnclosingScrollPane() {
                            // do nothing, custom table header
                        }
                    };
                    JScrollPane pane = new JScrollPane(table);
                    pane.setColumnHeaderView(new JLabel("Hi!"));
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(pane);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    
  • Order of JTable

    Hello

    I want to sort the rows in a table, but I'm a little arrested. I would like to move the empty cells to the bottom of the table at any time. This works if the direction of the order is ascending, otherwise the cells will be at the top of the table. Anyone can propose a solution to this problem?
    public class Table {
    
    private static JFrame frame;
    private static JScrollPane scrollPane;
    private static JTable table;
    private static String[] columns;
    private static String[][] rows;
    
    static {
        rows = new String[][]{{"apple"}, {"pear"}, {"banana"}, {"paradise"}, {""}, {""}};
        columns = new String[]{"Fruits"};
    }
    
    public static void main(String[] args) {
        frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(table(), BorderLayout.PAGE_START);
        frame.setResizable(false);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
    
    private static JScrollPane table() {
        table = new JTable(rows, columns);
        TableRowSorter tableRowSorter = new TableRowSorter(table.getModel());
        tableRowSorter.setComparator(0, new Comparator<String>() {
    
        @Override
        public int compare(String s1, String s2) {
            if (s1.isEmpty() && s2.isEmpty()) {
                return 0;
            } else if (s1.isEmpty() && !s2.isEmpty()) {
                return 1;
            } else if (!s1.isEmpty() && s2.isEmpty()) {
                return -1;
            }
            return s1.compareTo(s2);
        }
        });
        table.setRowSorter(tableRowSorter);
        scrollPane = new JScrollPane(table);
        return scrollPane;
    }
    }

    Sort the JTable with a blank line

    DB

  • Registration of fixed pixels in preset locations, then compare these pixels.

    Hello world.

    I am absolutely new to the development of a plugin and have been plowed by the SDK and the sample of projects so far, but I had a few questions on the approach to what I want to achieve and thought that it would be better to pick the brain of everyone here.

    I need to compare images from a video to an image of the sample source, which I will refer to the target. I found how to do this using the example of the Fund and the tutorial on to Mactech. However, the problem becomes complex when I need to compare only the pixels of the source image fixed to some fixed pixels in the target image. To give a better idea, I think I should better describe the problem statement.

    Scenario:

    A user saves an image of the target as well as fixed pixels for the purposes of comparison as a preset. Also, the user chooses the fixed pixels in a test source frame and records this as well. The plugin takes the video source and the preset as an input and compares the fixed pixels to the pixels of the target. By 'compare', I mean some math complex would be conducted in space CIE Lab, but this is a debate for later, and I take a step at a time.

    Anyone can guide me please on how to implement this system first?

    In short:

    1. how to store the x and y of fixed pixels in a test frame source and target 2 presets? Possibly a custom data structure that should be delivered with the image?

    2. How do access and iterate only through those fixed pixels in a raster image and source target?

    I'm sorry if these are silly questions, but I have read for a while and seem not to be able to get these answers.

    Thank you

    Chirag

    Hello chirag_raman!

    Welcome to our little forum, where everyone has an opinion, but no one knows for sure. :-)

    what you ask is not complex, so let's address the issues:

    1. how to save a set of coordinates x, y:

    I would say that depends especially how the user let's you know what are these coordinates.

    I guess the easiest way would be to use a setting point.

    You can keep the coordinates in a param point and hidden where you do not want the user to see.

    but there are two other ways of keeping data with a plug-in.

    You can use a param 'arbitrary' type, or use the sequence_data.

    device to store a data structure that you create are all two meanings. You can put whatever you want in it.

    both methods allow you to change the size of the data stored in (almost) any time.

    in both cases, the data is stored with the project file. (unless you don't want it)

    the differences are:

    sequence_data-

    you have only one instance of your plug-in.

    you manage the evolution of the data, and it is not cached in the undo stack.

    a change in the data does not have a new rendering.

    arbitrary param-

    You can have as many as you wish in each plugin.

    a change to data in this setting is cancelled by the user.

    a change causes a new rendering.

    Look at the example "ColorGrid" for how to handle an arbitrary param and the 'Supervisor' sample for how to manage the sequence_data.

    2. how to access specific pixels.

    a couple of ways.

    You can use the rest of the sample to retrieve the color of a pixel/subpixel/a buffer zone,

    or you can directly access the position in RAM and enter the data yourself.

    Look at the sample 'shifter' to see the rest of the sample in action and the 'CCU' to see how to access directly the position in ram.

    I hope this helps.

    Cheers!

    :-)

  • The line between two labels

    Hello world

    I wrote this little program where iam creating two label and I can drag this label and this works perfectly.
    I also try to include a line between this label. I am not getting the correct result because I see my tag, but not the line. (I know that my program is incomplete to separating it from the label, since I can't see the line with label iam not able to proceed)

    I am a newbie so my code is perhaps not too professional. Hoping to find a few tips.
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.geom.Line2D;
    
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    public class test extends JFrame implements MouseListener, MouseMotionListener  {
    
    private JPanel panel = new JPanel(null);   
    private JLabel label1 = new JLabel();
    private JLabel label2 = new JLabel();
    private int mouseX = 200;
    private int mouseY = 100;
    private boolean drag = false;
    
    
    public test() {
        this.add(panel);
        panel.setBackground(Color.WHITE);
    
        panel.add(label1);
        label1.setOpaque(true);
        label1.setBackground(Color.BLUE);
        label1.setBounds(mouseX, mouseY, 100, 50);
        label1.addMouseMotionListener(this);
        label1.addMouseListener(this);
    
        panel.add(label2);
        label2.setOpaque(true);
        label2.setBackground(Color.RED);
        label2.setBounds(mouseX + 200, mouseY, 100, 50);
        label2.addMouseMotionListener(this);
        label2.addMouseListener(this);
          
    }
    
    @Override
    public void mousePressed(MouseEvent e) {
        if (e.getSource() == label1) {
            drag = true;
        }
        if (e.getSource() == label2) {
            drag = true;
        }
    }
    
    
    
    @Override
    public void mouseReleased(MouseEvent e) {
        drag = false;
    }
    
    @Override
    public void mouseDragged(MouseEvent e) {
          if (drag == true)
        {
            JComponent jc = (JComponent)e.getSource();
            jc.setLocation(jc.getX()+e.getX(), jc.getY()+e.getY());
        }
    }
    
    public void mouseMoved(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void mouseClicked(MouseEvent e) {}
    
    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        Line2D lin = new Line2D.Float(100, 100, 250, 260);
        g2.draw(lin);
        super.paint(g2);
    }
    
    public static void main(String[] args) {
        test frame = new test();
        frame.setVisible(true);
        frame.setSize(600, 400);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
       
    }
    }
    Thanks for all your time and help.

    Outside of the Netbeans IDE is also there another tool that can help in creating faster GUI swing application.
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2 = (Graphics2D) g;
        Line2D lin = new Line2D.Float(100, 100, 250, 260);
        g2.draw(lin);
    }
    

    Also I suggest

    public void mousePressed(MouseEvent e) {
        if (e.getSource() == label1 || e.getSource() == label2) {
            drag = true;
        }
    }
    
  • Help with the drawing of a recursive tree

    Hello
    I tried to draw a kind of recursive tree similar to this , but I got stuck. I can not write the actual recursion and I ask for some help how to.
    import java.awt.*;
    import javax.swing.*;
    
    public class Tree extends JPanel{
    
         static void drawTree(Graphics2D g, int n, int x, int y,
                                          int x1, int y1, int x2, int  y2, int x3, int y3){
              
              if(n==0){
                   return;
              }
              else{
                   g.setColor(Color.BLUE);
                   g.translate(x, y);     // Moves to center of the screen
                   g.rotate(180*Math.PI/180);
                   g.drawLine(0, 0, x1, y1);
                   g.drawLine(0, 0, x2, y2);     // Draws main three lines
                   g.drawLine(0, 0, x3, y3);
                   g.rotate(-180*Math.PI/180);     // Still at the center
                   
                   g.translate(-x1, -y1);     // Moves to the top of the left line
                   g.rotate(150*Math.PI/180);
                   g.drawLine(0, 0, x1/2, y1/2);
                   g.drawLine(0, 0, x2/2, y2/2);     // Draws first combination
                   g.drawLine(0, 0, x3/2, y3/2);
                   g.rotate(-150*Math.PI/180);
                   g.translate(x1, y1);     // Moves back to center
                   
                   g.translate(-x2, -y2);     // Moves to the top of the middle line
                   g.rotate(180*Math.PI/180);
                   g.drawLine(0, 0, x1/3, y1/3);
                   g.drawLine(0, 0, x2/3, y2/3);     // Draws second combination
                   g.drawLine(0, 0, x3/3, y3/3);
                   g.rotate(-180*Math.PI/180);
                   g.translate(x2, y2);     // Moves back to center
                   
                   g.translate(-x3, -y3);     // Moves to the top of the right line
                   g.rotate(210*Math.PI/180);
                   g.drawLine(0, 0, x1/2, y1/2);
                   g.drawLine(0, 0, x2/2, y2/2);     // Draws third combination
                   g.drawLine(0, 0, x3/2, y3/2);
                   g.rotate(-210*Math.PI/180);
                   g.translate(x3, y3);     // Moves back to center
                   
                   g.setColor(Color.RED);
                   g.drawLine(0, 0, 50, 0);
                   g.drawLine(0, 0, 0, 50); // Draws coordinate system just for my reference
                   g.drawLine(0, 0, -50, 0);
                   
              }
              
         }
         
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              
              drawTree((Graphics2D)g, 5, getWidth()/2, getHeight()/2, 40, 20, 10, 15, -40, 20 );
              
         }
         
         
         public static void main(String[] args) {
              
              Tree panel = new Tree();
              JFrame app = new JFrame("Tree");
              
              app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              app.add(panel);
              app.setSize(500, 500);
              app.setVisible(true);
         }
    
    }
    For now, I'm worried about the stem. Just the branches.

    Any help/advice is greatly appreciated.

    Published by: Luke on May 1st, 2011 17:04

    Luke wrote:
    The left branches seem to decrease length very well when I go deep.

    But there are two problems that I don't know how fix - length of branches straight is too much decreasing and they are misplaced. The other thing is that when I

    maximize/minimize the window containing the graph the image becomes smaller and smaller until it becomes a small point.

    You are far too complicated. But the static variable can actually help you visualize how the tree is painted. run the program below to see.

    I set a goal:
    -Each recursive call must paint a line 10 pixels of length less than the forward direction. Specifically in the program below should be the length
    line 1: 100px
    line 2, 5: 90px
    line 3, 4, 6, 7: 80px
    -You can use n, x and y to the length calculated
    -You can add additional parameters to the draw method
    -You are not allowed to use instance variables (you can leave the variable count for debugging)
    -You are not allowed to use the static keyword anywhere
    -You have to give the result of each calculation a descriptive name

    // For example not:
    draw((Graphics2D) g, 3, getWidth() / 2, getHeight() / 2);
    // but
    int depth = 3;
    int centerHorizontally = getWidth() / 2;
    int centerVertically = getHeight() / 2;
    draw((Graphics2D) g, depth, centerHorizontally, centerVertically);
    
    import java.awt.*;
    import javax.swing.*;
    
    public class Tree extends JPanel {
    
        private int count;
    
        private void draw(Graphics2D g, int n, int x, int y) {
            if (n == 0) {
                return;
            }
            else {
                int angle = 35;
                int length = 50;
                count++;
    
                g.drawLine(x, y, x, y - length); // trunk
                g.setColor(Color.RED);
                g.drawString(String.valueOf(count), x + 2, y - (length / 2));
                g.setColor(Color.BLACK);
    
                g.rotate(Math.toRadians(-angle), x, y - length); // left
                                                                         // branch
                draw(g, n - 1, x, y - length);
                g.rotate(Math.toRadians(angle), x, y - length);
    
                g.rotate(Math.toRadians(angle), x, y - length); // right
                                                                        // branch
                draw(g, n - 1, x, y - length);
                g.rotate(Math.toRadians(-angle), x, y - length);
    
            }
        }
    
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            count = 0;
    
            Graphics2D gg = (Graphics2D) g;
            gg.setFont(gg.getFont().deriveFont(Font.BOLD, 16f));
            gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            draw(gg, 3, getWidth() / 2, getHeight() / 2);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Tree tree = new Tree();
                    tree.setPreferredSize(new Dimension(500, 500));
    
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(tree);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    

    Published by: Walter Laan 11 May 2011 21:58 (a little more readable numbers :))

  • Tranlation required: Basic in the &lt; g &gt; sense code

    Hello readers of stock code,.

    just ran across a method that leaves me speechless (translated into: confused like puzzle). In BasicTableHeaderUI, it is called by the mouseDragged when resizing, the calling code is more or less simple (just do an internal accounting with the return value. Here you go, JW comments are mine:
        private int changeColumnWidth(TableColumn resizingColumn,
                                      JTableHeader th,
                                      int oldWidth, int newWidth) {
            resizingColumn.setWidth(newWidth);
            
            Container container;
            JTable table;
    // JW: don't care if the header is standalone or not in a JScrollPane
            if ((th.getParent() == null) ||
                ((container = th.getParent().getParent()) == null) ||
                !(container instanceof JScrollPane) ||
                ((table = th.getTable()) == null)) {
                return 0;
            }
    
            if (!container.getComponentOrientation().isLeftToRight() &&
                    !th.getComponentOrientation().isLeftToRight()) {
    // JW: RtoL orientation requires ... 
                    JViewport viewport = ((JScrollPane)container).getViewport();
                    int viewportWidth = viewport.getWidth();
                    int diff = newWidth - oldWidth;
                    int newHeaderWidth = table.getWidth() + diff;
    
                    /* Resize a table */
                    Dimension tableSize = table.getSize();
                    tableSize.width += diff;
    // JW: resize the table? why's that ... should happen automatically on column.setWidth
                    table.setSize(tableSize);
    
                    /* If this table is in AUTO_RESIZE_OFF mode and
                     * has a horizontal scrollbar, we need to update
                     * a view's position.
                     */
                    if ((newHeaderWidth >= viewportWidth) &&
                        (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                        Point p = viewport.getViewPosition();
                        p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth,
                                                   p.x + diff));
    // JW: auto-resize-off requires to update viewPosition. Again, why ... would 
    // expect the autoscroll to handle this case  
                        viewport.setViewPosition(p);
                        return diff;
                }
            }
    // JW: if we get here, no need to return anything
            return 0;
        }
    Commenting on those indeed leads to a weird behavior. Code looks like a Gash around something, but what exactly is at its base? What class is the culprit?

    Comments welcome!

    See you soon
    Jeanette

    First of all, I thought it was related to this auto scroll does not work because of drag events are generated for the header of the table, not the table. I have a workaround for column dragging this volutes with auto resize table off. But when resizing you really want the position of the edge of the column you resize not to stay in the same position on the screen.

    So the problem is who is being paid to the ScrollPane, is that "grows to the right" - that's if its width expands display remains fixed in LTR position. For real RTL desired display position so that the illusion is that the point of view remains fixed and the scroll bar 'grows to the left.
    Tried to move the position of ScrollPaneLayout #layoutContainer display that works keeping the fixed sight but the column sizing is now off because it does not properly handle inappropriate display position (essentially the return by this method of changeColumnWidth mouseXOffset). If the header of table user interface still needs to compensate for the displacement of view position.

    Do not know what about the table.setSize () and it seems unnecessary.

    Change of ScrollPaneLayout is not complete, it must also adjust the position of the display when the pane scroll itself is made smaller, so it "pushes left' in rtl as well (drag the smaller frame to see).

    Note that the code of orginalBasicTableHeaderUI seems to have a bug (try to resize small and keep dragging the mouse to the right (in the rtl orientation))-> resizing gets stuck. I don't see with my code below :).

    import java.awt.*;
    import javax.swing.*;
    
    public class TestColumnResize {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JTable table = new JTable(3, 3);
                    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    table.getTableHeader().setUI(new MyTableHeaderUI());
                    JScrollPane scroll = new JScrollPane(table);
                    scroll.setLayout(new ScrollPaneLayout() {
                        private int oldWidth = -1;
    
                        @Override
                        public void layoutContainer(Container parent) {
                            super.layoutContainer(parent);
                            if(getViewport().getComponentOrientation().isLeftToRight()) {
                                return;
                            }
                            int width = getViewport().getView().getWidth();
                            if(oldWidth != -1 && oldWidth < width
                                    && width > getViewport().getWidth()) {
                                Component view = getViewport().getView();
                                if(view instanceof Scrollable
                                        && ((Scrollable) view).getScrollableTracksViewportWidth()) {
                                    return;
                                }
                                int offset = width - oldWidth;
                                Point p = getViewport().getViewPosition();
                                p.x += offset;
                                getViewport().setViewPosition(p);
                            }
                            oldWidth = width;
                        }
                    });
    
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(scroll);
                    frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    
    // modified code in MyTableHeaderUI#changeColumnWidth
            if (!container.getComponentOrientation().isLeftToRight() &&
                    !th.getComponentOrientation().isLeftToRight()) {
                JViewport viewport = ((JScrollPane)container).getViewport();
                int viewportWidth = viewport.getWidth();
                int diff = newWidth - oldWidth;
                int newHeaderWidth = table.getWidth() + diff;
    
                if ((newHeaderWidth >= viewportWidth) &&
                        (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                    return diff;
                }
            }
    
  • Update of JFrame/JDialog

    I want to update a JFrame, but it does not work. I did a code example. If I click on the Ok button, nothing happens. Could someone help me what is the problem?
    public class Main implements ActionListener {
    
        private JButton button;
        private JButton button2;
        private JFrame frame;
        private JPanel ok;
        private JPanel cancel;
    
        public static void main(String[] args) {
            new Main();
        }
    
        public Main() {
            frame = new JFrame("Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(ok(), BorderLayout.PAGE_START);
            frame.setResizable(false);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    
        private JPanel ok() {
            button = new JButton("Ok");
            button.addActionListener(this);
            ok = new JPanel();
            ok.add(button);
            return ok;
        }
    
        private JPanel cancel() {
            button2 = new JButton("Cancel");
            button2.addActionListener(this);
            cancel = new JPanel();
            cancel.add(button2);
            return cancel;
        }
    
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == button) {
                frame.removeAll();
                frame.add(cancel(), BorderLayout.PAGE_START);
                frame.pack();
                frame.validate();
                frame.repaint();
            } else if (e.getSource() == button2) {
                System.exit(0);
            }
        }
    }

    Use frame.getContentPane () .removeAll (). Only add/remove are the transmission to the IIRC content pane.

  • How to add buttons/text to the component right when the selection is made from the left pane

    Hello

    I am new to the JAVA swing development.

    I am creating an application where in the pane on the left, there is a tree Menu and in the right pane, I have a few buttons. In view of the options in the left pane, I should be able to add more buttons and or the text to the right pane.

    How to achieve this? If you guys have any example code, please post or suggest ways to accomplish.

    Thanks in advance.
    user2325986

    It seems that you declare leftPane, rightPane and different main_Frame and have too much static and final elements. Look at the code below. I put GridBagLayout to the framework for a better look.

    I don't know what you mean when you say that you only want to right panel and you want to add. Also, I think you'd be better off using CardLayout to right panel as stated jduprez

    When you want to display using code {_code_} code here {_code_} (code in parentheses without underscores) tags

    Here is a working example of what you had:

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import javax.swing.tree.*;
    
    public class Main
    {
        public static void main(String[] args)
        {
            main_Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            main_Frame.setVisible(true);
        }
    
        public static TestFrame main_Frame = new TestFrame();
    }
    
    class TestFrame extends JFrame
    {
        public TestFrame()
        {
            setTitle("Test Frame");
            setSize(500, 500);
            setLayout(new GridBagLayout());
    
            leftGBC = new GridBagConstraints();
            leftGBC.gridx = 0;
            leftGBC.gridy = 0;
            leftGBC.fill = leftGBC.BOTH;
            leftGBC.weightx = 10;
            leftGBC.weighty = 100;
    
            rightGBC = new GridBagConstraints();
            rightGBC.gridx = 1;
            rightGBC.gridy = 0;
            rightGBC.fill = rightGBC.BOTH;
            rightGBC.weightx = 100;
            rightGBC.weighty = 100;
    
            leftPanel = new JPanel();
            leftPane = new JScrollPane(leftPanel);
            leftPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            leftPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    
            rightPanel = new JPanel();
            rightPane = new JScrollPane(rightPanel);
            rightPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            rightPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("main_Tree");
            DefaultMutableTreeNode Branch1 = new DefaultMutableTreeNode("Branch1");
            DefaultMutableTreeNode Leaf1 = new DefaultMutableTreeNode("Leaf1");
            root.add(Branch1);
            Branch1.add(Leaf1);
            DefaultMutableTreeNode Branch2 = new DefaultMutableTreeNode("Branch2");
            DefaultMutableTreeNode Leaf2 = new DefaultMutableTreeNode("Leaf2");
            root.add(Branch2);
            Branch2.add(Leaf2);
            JTree tree = new JTree(root);
            tree.setRootVisible(true);
            tree.setShowsRootHandles(true);
            tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    
            tree.addTreeSelectionListener(new TreeSelectionListener()
            {
                public void valueChanged(TreeSelectionEvent se)
                {
                    JTree tree = (JTree) se.getSource();
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                    if (node == null) return;
                    String nodeInfo = node.toString();
    
                    if (nodeInfo.equals("Leaf1"))
                    {
                        rightPanel = new JPanel();
                        rightPanel.add(label);
                        Main.main_Frame.remove(rightPane);
                        rightPane = new JScrollPane(rightPanel);
                        rightPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                        rightPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                        Main.main_Frame.add(rightPane, rightGBC);
                        Main.main_Frame.validate();
                        Main.main_Frame.repaint();
                    }
    
                    if (nodeInfo.equals("Leaf2"))
                    {
                        rightPanel = new JPanel();
                        rightPanel.add(Jbt2);
                        Main.main_Frame.remove(rightPane);
                        rightPane = new JScrollPane(rightPanel);
                        rightPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                        rightPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                        Main.main_Frame.add(rightPane, rightGBC);
                        Main.main_Frame.validate();
                        Main.main_Frame.repaint();
                    }
                }
            });
    
            DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
            tree.setRowHeight(30);
    
            renderer.setLeafIcon(new ImageIcon("blue-ball.gif"));
            renderer.setOpenIcon(new ImageIcon("red-ball.gif"));
            renderer.setClosedIcon(new ImageIcon("yellow-ball.gif"));
            renderer.setFont(new Font("Monospaced",Font.BOLD|Font.ITALIC,15));
            renderer.setTextNonSelectionColor(Color.blue);
            renderer.setTextSelectionColor(Color.white);
            renderer.setBackgroundNonSelectionColor(Color.white);
            renderer.setBackgroundSelectionColor(Color.gray);
            renderer.setBorderSelectionColor(Color.lightGray);
    
            leftPanel.add(tree);
    
            add(leftPane, leftGBC);
            add(rightPane, rightGBC);
        }
    
        private JPanel leftPanel;
        private JPanel rightPanel;
        private JScrollPane leftPane;
        private JScrollPane rightPane;
        private GridBagConstraints leftGBC;
        private GridBagConstraints rightGBC;
    
        private JButton Jbt1 = new JButton("Button1");
        private JButton Jbt2 = new JButton("Button2");
    
        private JLabel label = new JLabel("Enter your message below");
        private JTextArea jta = new JTextArea(10,15);
    
        private JButton Jbt3 = new JButton("Button3");
        private JButton Jbt4 = new JButton("Button4");
    }
    
  • JWindow with border

    Hello

    Since JWindow cannot be given a border, I tried to write my own JWindow - but nothing is painted at all.
    import java.awt.*;
    import javax.swing.*;
    
    public class WindowTest {
    
      public JPanel createContentPane() {
        JPanel panel= new JPanel();
        MyWindow mw= new MyWindow();
        mw.setSize(200,150);
        mw.setLocation(50, 50);
        mw.getContentPane().setBackground(Color.YELLOW);
        mw.getContentPane().add(new JLabel("Hello"));
        mw.setVisible(true);
        return panel;
      }
    
    
      void createAndShowGUI() {
        JFrame frame= new JFrame("Window Test");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(300,300);
        frame.setContentPane(createContentPane());
        frame.setVisible(true);
      }
    
    
      public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
         new WindowTest().createAndShowGUI();
          }
        });
      }
    
    
      class MyWindow extends JWindow {
        MyWindow() {
          super();
        }
    
        public void paint(Graphics g) {
          super.paint(g);
          Dimension dim= getSize();
          System.out.println(dim);
          g.setColor(Color.BLACK);
    //      g.drawRect(0, 0, dim.width, dim.height);
          g.drawRect(5, 5, dim.width-5, dim.height-5);
        }
      }
    
    }

    Since JWindow cannot be given to a border,

    window.getRootPane().setBorder(new MatteBorder(4, 4, 4, 4, Color.BLUE));
    
  • JWindow and absolute layout

    Hello

    When you run the following code, you see the label 'Line 2' in the JWindow
    lost, although the position controlled with getBounds()'s alright.
    What Miss me?
    import java.awt.*;
    import javax.swing.*;
    
    public class WindowTest {
      JFrame frame;
    
      public JPanel createContentPane() {
        JPanel panel= new JPanel();
        createAndShowWindow();
        return panel;
      }
    
    
      void createAndShowGUI() {
        frame= new JFrame("Window Test");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(300,300);
        frame.setContentPane(createContentPane());
        frame.setVisible(true);
      }
    
    
      private void createAndShowWindow() {
        JWindow win= new JWindow(frame);
        win.setSize(120, 90);
        win.setLocation(90, 50);
        Container cp= win.getContentPane();
        cp.setBackground(Color.YELLOW);
        JLabel lb= new JLabel("<html><u>Header</u></html>");
        lb.setBounds(35,5, 80,20);
        cp.add(lb);
        for (int i=0; i<2; i++) {
          lb= new JLabel("Line "+(i+1));
          lb.setBounds(10,i*20+30, 80,20);
          cp.add(lb);
          System.out.println(lb.getBounds());
        }
    /*
    Same result without loop
          lb= new JLabel("Line 1");
          lb.setBounds(10,30, 80,20);
          cp.add(lb);
          System.out.println(lb.getBounds());
          lb= new JLabel("Line 2");
          lb.setBounds(10,50, 80,20);
    //      lb.setBounds(50,70, 80,20); // You can set any position, the label won't 
    
    move.
          cp.add(lb);
          System.out.println(lb.getBounds());
    */
        win.setVisible(true);
      }
    
    
      public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
         new WindowTest().createAndShowGUI();
          }
        });
      }
    
    }

    nothing complicated (sorry if I'm wrong), than because default page is FlowLayout and then you miss, I think that wokrs with

    
    win.setLayout(null);
    
  • By CellEditor as CellRenderer in JTable using custom

    I have a very complex JTable implementation that allows the user to change data of the database where the data types control what will be the editor in each cell, for example checkboxes, comboboxes, components datepicker and so on. The converters are for the most part, labels and sometimes images (for checkboxes for example). It works very well with the current implementation. Now, I have a request to change the implementation so that the user can see which components are in cells without having to click on the cell. In other words, I want to show the editor as my renderer. I tried to do it by simply returning the editor in my getTableCellRendererComponent, but the problem is that when I have several lines in the table the values in a row are copied to the next line when you click on back between cells.

    I made a simple example to illustrate the problem. If you run it for example "a" in the first cell of the first row, and then click the first cell of the second row 'a' also appears in that cell. If you enter 'b' in this cell, click the first cell again, it will be a 'b '.

    When this debug in my real application, I see that the editor in Chief of the cell, I'm clicking is created first with the correct value ('a') and after that I get stopEditing on the cell, I was leaving that creates the editor-in-Chief of this cell with the value ('b'). After that 'b' is in the editor for the cell clicked in (even if it is 'a' shortly before that). It seems to me that you are not supposed to have publishers simultaneously on different lines. If I could get the stopEditing before the call to prepareRenderer I think it would work, but it looks at the stack trace those calls come from java classes (not something I can change). I have all the cells on a line in editing at the same time without problems, but not several lines at once.

    Can someone tell me in all directions on that?
    Thank you
    Sara
    import java.awt.Component;
    import java.awt.FlowLayout;
    
    import javax.swing.*;
    import javax.swing.table.*;
    
    public class EditorAsRendererTableTest
        extends JFrame
    {
        JScrollPane myPane;
        JTable      myTable;
    
        public static void main(String[] args)
        {
            EditorAsRendererTableTest t = new EditorAsRendererTableTest();
            t.initComponents();
            t.createUI();
            t.pack();
            t.setVisible(true);
        }
    
        private void initComponents()
        {
            myTable = new MyJTable(3, 2);
            myPane = new JScrollPane();
            myPane.getViewport().add(myTable);
            myTable.setFillsViewportHeight(true);
        }
    
        private void createUI()
        {
            this.setLayout(new FlowLayout());
            getContentPane().add(myPane);
        }
    
        private class MyJTable
            extends JTable
        {
            public MyJTable(int rows, int cols)
            {
                super(rows, cols);
                TableColumnModel colModel = getColumnModel();
                colModel.getColumn(0).setCellEditor(new MyCellEditor());
                colModel.getColumn(0).setCellRenderer(new MyCellRenderer());
            }
        }
    
        private class MyCellRenderer
            implements TableCellRenderer
        {
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column)
            {
                // return new JLabel((String)value);
                return table.getCellEditor(row, column).getTableCellEditorComponent(table, value, isSelected, row, column);
            }
        }
    
        private class MyCellEditor
            extends AbstractCellEditor
            implements TableCellEditor
        {
    
            JFormattedTextField editor;
    
            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
            {
                if (editor == null) {
                    editor = new JFormattedTextField();
                }
                editor.setValue(value);
                return editor;
            }
    
            public Object getCellEditorValue()
            {
                return editor.getValue();
            }
    
        }
    }

    Just can't use JFormattedTextField correctly, see below (you still need to add selected/focus handling however).

    import java.awt.Component;
    import java.awt.EventQueue;
    import java.text.DecimalFormat;
    import java.text.ParseException;
    
    import javax.swing.*;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumnModel;
    
    public class EditorAsRendererTableTest {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JTable table = new JTable(3, 2);
                    TableColumnModel colModel = table.getColumnModel();
                    MyCellEditor both = new MyCellEditor();
                    colModel.getColumn(0).setCellEditor(both);
                    colModel.getColumn(0).setCellRenderer(both);
    
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(new JScrollPane(table));
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    
        private static class MyCellEditor extends AbstractCellEditor implements TableCellEditor,
                TableCellRenderer {
    
            JFormattedTextField renderer = new JFormattedTextField(DecimalFormat.getInstance());
            JFormattedTextField editor;
    
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                renderer.setValue(value);
                return renderer;
            }
    
            public Component getTableCellEditorComponent(JTable table, Object value,
                    boolean isSelected, int row, int column) {
    
                editor = new JFormattedTextField(DecimalFormat.getInstance());
                editor.setValue(value);
                return editor;
            }
    
            @Override
            public boolean stopCellEditing() {
                try {
                    editor.commitEdit();
                }
                catch (ParseException e) {
                    return false;
                }
    
                return super.stopCellEditing();
            }
    
            public Object getCellEditorValue() {
                return editor.getValue();
            }
        }
    }
    
  • Test bandwidth Profiler only 2 frames?

    Hey all,.

    I have a Flash animation that I have created, which spans 1800 frames. When I test the movie, it plays properly. However, the bandwidth Profiler displays as two managers. Where is my 'play' button and the other containing the rest of the frames. How is my bandwidth Profiler does not correctly display the timeline? The reason I ask is because a preloader that I try to use does not work. I guess that it is dysfunctional because of this problem. My code must be correct, because I used the same code and preloader for another Flash animation, and everything works as it should, preloader included.

    Here is a picture of what I see for my Flash animation that does not work correctly: http://www.flickr.com/photos/90130393@N08/8185730489/

    Where it says, "duration" should say 1800 fr., but instead said: "2 fr." However, when I remove the name of the instance of my preloader, the bandwidth Profiler shows everything as it should be with the correct time, but of course my preloader does not accordingly.

    I think that it is the root of my problem which is causing my preloader not working.

    That's the problem.  you are using, at least one, tlf textfield.  is it necessary?

    If this is not the case, use the classic text.

    If Yes, click on file > publishing settings > settings (the wrench) actionscript > library path > and change the combobox default binding to "merged into code".

    Repeat the test.

    p.s. Please check the useful/correct.

Maybe you are looking for