How to add mouse listener for a single row alone

I have a requirement. In a JTable when I double click a particular row the cells in the row should set to the width which I have provided.
The problem with my code is when I click fourth row in the table, the first row gets adjusted.
So how I need help is
only if I click the first row, the first row cell size should get adjusted not when I click fourth row.
Similarly if I give some cell width and height for fourth row cells, then when I double click the fourth row, the fourth should alone get adjusted and not the other rows.
Hope I have explained clearly.
How can it be achieved?
Please find below my code. Everything is hardcoded. So it may look messy. Please excuse.
// Imports
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
class SimpleTableExample extends JFrame {
// Instance attributes used in this example
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
String data1 = "";
String data2 = "123456789ABCDEFGHIJKLMNOPQRSTUVQWXYZabcdefghijklmnopqrstuvwxyzaquickbrownfoxjumpedoverthelazydog";
int size = data2.length();
// Constructor of main frame
public SimpleTableExample() {
     // Set the frame characteristics
     setTitle("Simple Table Application");
     setSize(400, 200);
     setBackground(Color.gray);
     // Create a panel to hold all other components
     topPanel = new JPanel();
     topPanel.setLayout(new BorderLayout());
     getContentPane().add(topPanel);
     // Create columns names
     String columnNames[] = { "SEL", "DESIGN DATA", "PART NUMBER" };
     // Create some data
     String dataValues[][] = { { data1, data2, "67", "77" },
          { "", "43", "853" }, { "", "89.2", "109" },
          { "", "9033", "3092" } };
     DefaultTableModel model = new DefaultTableModel(dataValues, columnNames);
     model.addColumn("PART TITLE");
     model.addColumn("SPECIAL INSTRUCTIONS");
     table = new JTable(model) {
     public boolean isCellEditable(int rowIndex, int colIndex) {
          return false;
     // set specific row height
     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     int colInd = 0;
     TableColumn col = table.getColumnModel().getColumn(colInd);
     int width = 50;
     col.setPreferredWidth(width);
     int colInd2 = 1;
     TableColumn col2 = table.getColumnModel().getColumn(colInd2);
     int width2 = 100;
     col2.setPreferredWidth(width2);
     int colInd3 = 2;
     TableColumn col3 = table.getColumnModel().getColumn(colInd3);
     int width3 = 10;
     col3.setPreferredWidth(width3);
     int colInd4 = 3;
     TableColumn col4 = table.getColumnModel().getColumn(colInd4);
     int width4 = 10;
     col4.setPreferredWidth(width4);
     int colInd5 = 4;
     TableColumn col5 = table.getColumnModel().getColumn(colInd5);
     int width5 = 10;
     col5.setPreferredWidth(width5);
     table.addMouseListener(new MouseAdapter() {
     public void mouseClicked(MouseEvent e) {
          if (e.getClickCount() == 2) {
          JTable target = (JTable) e.getSource();
          int row = target.getSelectedRow();
          int column = target.getSelectedColumn();
          TableColumn col1 = table.getColumnModel().getColumn(0);
          col1.setPreferredWidth(50);
          TableColumn col2 = table.getColumnModel().getColumn(1);
          col2.setPreferredWidth(400);
          table.getColumnModel().getColumn(1).setCellRenderer(
               new TableCellLongTextRenderer());
          table.setRowHeight(50);
          TableColumn col5 = table.getColumnModel().getColumn(4);
          col5.setPreferredWidth(200);
     // Create a new table instance
     // table = new JTable(dataValues, columnNames);
     // Add the table to a scrolling pane
     scrollPane = new JScrollPane(table);
     topPanel.add(scrollPane, BorderLayout.CENTER);
// Main entry point for this example
public static void main(String args[]) {
     // Create an instance of the test application
     SimpleTableExample mainFrame = new SimpleTableExample();
     mainFrame.setVisible(true);
class TableCellLongTextRenderer extends JTextArea implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
     boolean isSelected, boolean hasFocus, int row, int column) {
     this.setText((String) value);
     this.setWrapStyleWord(true);
     this.setLineWrap(true);
     // set the JTextArea to the width of the table column
     setSize(table.getColumnModel().getColumn(column).getWidth(),
          getPreferredSize().height);
     if (table.getRowHeight(row) != getPreferredSize().height) {
     // set the height of the table row to the calculated height of the
     // JTextArea
     table.setRowHeight(row, getPreferredSize().height);
     return this;
Edited by: 915175 on Aug 3, 2012 4:24 AM

Hi
Try below code. Hope this will help
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
public class SimpleTableExample extends JFrame {
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
String data1 = "";
String data2 = "123456789ABCDEFGHIJKLMNOPQRSTUVQWXYZabcdefghijklmnopqrstuvwxyzaquickbrownfoxjumpedoverthelazydog";
int size = data2.length();
// Constructor of main frame
public SimpleTableExample() {
// Set the frame characteristics
setTitle("Simple Table Application");
setSize(400, 200);
setBackground(Color.gray);
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
// Create columns names
String columnNames[] = { "SEL", "DESIGN DATA", "PART NUMBER" };
// Create some data
String dataValues[][] = { { data1, data2, "67", "77" },
{ "", "43", "853" }, { "", "89.2", "109" },
{ "", "9033", "3092" } };
DefaultTableModel model = new DefaultTableModel(dataValues, columnNames);
model.addColumn("PART TITLE");
model.addColumn("SPECIAL INSTRUCTIONS");
table = new JTable(model) {
public boolean isCellEditable(int rowIndex, int colIndex) {
return false;
// set specific row height
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
int colInd = 0;
TableColumn col = table.getColumnModel().getColumn(colInd);
int width = 50;
col.setPreferredWidth(width);
int colInd2 = 1;
TableColumn col2 = table.getColumnModel().getColumn(colInd2);
int width2 = 100;
col2.setPreferredWidth(width2);
int colInd3 = 2;
TableColumn col3 = table.getColumnModel().getColumn(colInd3);
int width3 = 10;
col3.setPreferredWidth(width3);
int colInd4 = 3;
TableColumn col4 = table.getColumnModel().getColumn(colInd4);
int width4 = 10;
col4.setPreferredWidth(width4);
int colInd5 = 4;
TableColumn col5 = table.getColumnModel().getColumn(colInd5);
int width5 = 10;
col5.setPreferredWidth(width5);
// Cell Render should apply on each column -- add by Rupali
for(int i=0; i< table.getColumnModel().getColumnCount(); i++){
table.getColumnModel().getColumn(i).setCellRenderer( new TableCellLongTextRenderer());
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable target = (JTable) e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
setTableCellHeight(table,row,column); //Added by Rupali
TableColumn col1 = table.getColumnModel().getColumn(0);
col1.setPreferredWidth(50);
TableColumn col2 = table.getColumnModel().getColumn(1);
col2.setPreferredWidth(400);
TableColumn col5 = table.getColumnModel().getColumn(4);
col5.setPreferredWidth(200);
// Create a new table instance
// table = new JTable(dataValues, columnNames);
// Add the table to a scrolling pane
scrollPane = new JScrollPane(table);
topPanel.add(scrollPane, BorderLayout.CENTER);
* Created By Rupali
* This will set cell's height and column's width
* @param table
* @param row
* @param column
public void setTableCellHeight(JTable table, int row, int column) {
// set the JTextArea to the width of the table column
setSize(table.getColumnModel().getColumn(column).getWidth(),
getPreferredSize().height);
if (table.getRowHeight(row) != getPreferredSize().height) {
// set the height of the table row to the calculated height of the
// JTextArea
table.setRowHeight(row, getPreferredSize().height);
// Main entry point for this example
public static void main(String args[]) {
// Create an instance of the test application
SimpleTableExample mainFrame = new SimpleTableExample();
mainFrame.setVisible(true);
class TableCellLongTextRenderer extends JTextArea implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
this.setText((String) value);
this.setWrapStyleWord(true);
this.setLineWrap(true);
return this;
}

Similar Messages

  • How to set mouse listener for title bar of JFrame ?

    Hi, all
    How to we can set mouse listener for title bar of JFrame ?
    Please help

    Again, why did you not state this in your original
    question? Do we have to ask you every time what your
    actual requirement is?
    As I said in your last posting, if you don't give us
    the reuqirement in you question we can't help you.
    Sometimes your solution may be on the right track
    sometimes it isn't. We waste time guessing what your
    are trying to do if you don't give us the
    requirement.
    I gave you the answer in your other posting on this
    topic. The AWTEventListener can listen to events
    other than MouseEvents.
    The Swing tutorial has a list of most of the events.
    Pick the events you want to listen for:
    http://java.sun.com/docs/books/tutorial/uiswing/events
    /handling.htmlthe first, i am sory because my requirement not clear so that it wasted everybody time.
    The second, thank for your answer
    The third, AWTEvenListener do not support listener event on title bar
    but ComponentListener can know when we can change frame position.
    please see below that ComponentListener can handle action:
    public void componentHidden(ComponentEvent e) {
            displayMessage(e.getComponent().getClass().getName() + " --- Hidden");
        public void componentMoved(ComponentEvent e) {
            displayMessage(e.getComponent().getClass().getName() + " --- Moved");
        public void componentResized(ComponentEvent e) {
            displayMessage(e.getComponent().getClass().getName() + " --- Resized ");           
        public void componentShown(ComponentEvent e) {
            displayMessage(e.getComponent().getClass().getName() + " --- Shown");
        }Thanks for all supported your knowledge, you are great !

  • How to add multiple databases for a single frontend

    We have a project based on distributed databases and we have to workout on .Net framework.I want to know some information of connecting multiple databases for a single frontend and how can we access them.
    If so we have connected 2 databases for a single frontend in future if I want add one more database to it how it will be possible to do it without disturbing the current connectivity.
    Please help me in resolving this problem.
    Thanks......

    hi,
    what do you mean by connecting 2 databases? can you explain further?
    using entityframework you can connect to different databases
    public class CustomerContext : DbContext
    public ReportContext()
    : base("DefaultConnection")
    public DbSet<Customers> Customers { get; set; }
    and your connectionstring (config file)
    <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\\Database\Project.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>
    you can add more connection strings on it.
    https://msdn.microsoft.com/en-us/library/vstudio/cc716756(v=vs.100).aspx
    https://msdn.microsoft.com/en-us/library/ms254978(v=vs.110).aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • How to add Mouse Listener

    here is my code for my current project, it is to create a platform independent way to have a windows explore like window so far I have it displaying properly and all I need to do is when the user double clicks on a file itt should open up but thats where i need help, this is not homework
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.*;
    import sun.swing.*;
    import javax.swing.plaf.*;
    import java.io.*;
    import javax.swing.filechooser.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.basic.*;
    import java.lang.reflect.*;
    import java.beans.*;
    public class FileBrowserAttempt2  extends JFrame
         static FilePane Files;
         static JPanel Details;
         static JPanel list;
         static int activeView = 0;
         JFrame f;
        FileBrowserAttempt2 a = this;
        JPopupMenu pop;
        Action[] actions;
        JFileChooser toGetFileView;
         public  FileBrowserAttempt2(final JFileChooser toGetFileView) throws Exception
               try {
             // Set System L&F
            UIManager.setLookAndFeel(
                UIManager.getSystemLookAndFeelClassName());
             } catch(Exception e)
              Files = getFilePane(toGetFileView);               
                   view = Files.getViewMenu();
                   Details = Files.createDetailsView();
                   list = Files.createList();
                   pop = Files.getComponentPopupMenu();
                   actions = Files.getActions();
              pop.remove(view);
              for(Action Comp : actions)
                   System.out.println(Comp.getValue(Comp.NAME).toString());
              Component[] ary = toGetFileView.getComponents();
              setJMenuBar(createMenuBar());
              JPanel panel = new JPanel(new BorderLayout());
              panel.add(ary[0], BorderLayout.NORTH);
              panel.add(Files, BorderLayout.CENTER);     
              add(panel);
              setDefaultCloseOperation(3);
              pack();
              show();
         // THIS IS THE MOUSE LISTENER
         private class open extends  AbstractAction
                   public void actionPerformed(ActionEvent e)
                        try{
                        Class FileBrowser = FileBrowserAttempt2.this.Files.getClass();
                        Method a = FileBrowser.getMethod("getSelectedFile");
                        System.out.println("Action");
                        File open =(File) a.invoke(null);
                        Runtime.getRuntime().exec("cmd.exe start " + open.toString());
                        }catch(Exception ex)
                             ex.printStackTrace();
         public static void main (String[] args) throws Exception
               new FileBrowserAttempt2(new JFileChooser(new File("C:/")));
         public void printAry(Object[] ary)
              for(Object Comp : ary)
                   System.out.println(Comp.toString());
         private FilePane getFilePane(JFileChooser toGetFileView)
              Component[] components = toGetFileView.getComponents();
              for(Object Comp : components)
                   if(Comp instanceof FilePane)
                        return ((FilePane)Comp);
              return null;
         final JMenu view;
        private JMenuBar createMenuBar()
             JMenuBar menuBar = new JMenuBar();
             JMenu FileMen = new JMenu("File");        
             JMenuItem Exit = new JMenuItem("Exit");
             Exit.addActionListener(new ExitListener());
             FileMen.add(Exit);
             menuBar.add(FileMen);
             menuBar.add(view);
             return menuBar;
    class ExitListener implements ActionListener
         public void actionPerformed(ActionEvent e)
                  System.exit(0);
    }and here are the methods of FilePane
    public static final java.lang.String ACTION_APPROVE_SELECTION;
        public static final java.lang.String ACTION_CANCEL;
        public static final java.lang.String ACTION_EDIT_FILE_NAME;
        public static final java.lang.String ACTION_REFRESH;
        public static final java.lang.String ACTION_CHANGE_TO_PARENT_DIRECTORY;
        public static final java.lang.String ACTION_NEW_FOLDER;
        public static final java.lang.String ACTION_VIEW_LIST;
        public static final java.lang.String ACTION_VIEW_DETAILS;
        public static final int VIEWTYPE_LIST;
        public static final int VIEWTYPE_DETAILS;
        int lastIndex;
        java.io.File editFile;
        int editX;
    javax.swing.JTextField editCell;
        protected javax.swing.Action newFolderAction;
        public sun.swing.FilePane(sun.swing.FilePane$FileChooserUIAccessor);
        public void uninstallUI();
        protected javax.swing.JFileChooser getFileChooser();
        protected javax.swing.plaf.basic.BasicDirectoryModel getModel();
        public int getViewType();
        public void setViewType(int);
        public javax.swing.Action getViewTypeAction(int);
        public void setViewPanel(int, javax.swing.JPanel);
        protected void installDefaults();
        public javax.swing.Action[] getActions();
        protected void createActionMap();
        public static void addActionsToMap(javax.swing.ActionMap, javax.swing.Action[]);
        public javax.swing.JPanel createList();
        public javax.swing.JPanel createDetailsView();
        public javax.swing.event.ListSelectionListener createListSelectionListener();
        public javax.swing.Action getNewFolderAction();
        void setFileSelected();
        public void propertyChange(java.beans.PropertyChangeEvent);
        public void ensureFileIsVisible(javax.swing.JFileChooser, java.io.File);
        public void rescanCurrentDirectory();
        public void clearSelection();
        public javax.swing.JMenu getViewMenu();
        public javax.swing.JPopupMenu getComponentPopupMenu();
        protected sun.swing.FilePane$Handler getMouseHandler();
        protected boolean isDirectorySelected();
        protected java.io.File getDirectory();
        public static boolean canWrite(java.io.File);any help would be appreciated

    Its better you create your own panel to display each of the files, than to display the first element of the 'toGetFileView.getComponents()' In this way, you can add a mouse listener to each of those elements.

  • How to add 3 legends for a single series barchart?? JAVAFX

    Here is my code to generate 10 bars of different colors. I want to add legend respectively but it only one shows yellow legend
    1. I think it shows only 1 color because there is only 1 series. Is it possible to add more than 1 legend for a single series?
    or
    2. or can i display another image for legend in barchart??
    output :http://i.stack.imgur.com/fSNu7.png
    file i want to display in barchart:http://i.stack.imgur.com/cchch.png
    public class DynamicallyColoredBarChart extends Application {
        @Override
        public void start(Stage stage) {
            final CategoryAxis xAxis = new CategoryAxis();
            xAxis.setLabel("Bars");
            final NumberAxis yAxis = new NumberAxis();
            yAxis.setLabel("Value");
            final BarChart<String, Number> bc = new BarChart<>(xAxis, yAxis);
            bc.setLegendVisible(false);
            XYChart.Series series1 = new XYChart.Series();
            for (int i = 0; i < 10; i++) {
                // change color of bar if value of i is >5 than red if i>8 than blue
                final XYChart.Data<String, Number> data = new XYChart.Data("Value " + i, i);
                data.nodeProperty().addListener(new ChangeListener<Node>() {
                    @Override
                    public void changed(ObservableValue<? extends Node> ov, Node oldNode, Node newNode) {
                        if (newNode != null) {
                            if (data.getYValue().intValue() > 8) {
                                newNode.setStyle("-fx-bar-fill: navy;");
                            } else if (data.getYValue().intValue() > 5) {
                                newNode.setStyle("-fx-bar-fill: red;");
                series1.getData().add(data);
            bc.getData().add(series1);
            stage.setScene(new Scene(bc));
            stage.show();
        public static void main(String[] args) {
            launch(args);
    ...Edited by: 993431 on Mar 12, 2013 1:42 PM

    Either:
    1. Use a chart which displays multiple series, then you can allow the built-in legend to show OR
    2. Use a single dynamically colored series have you have done and create your own custom legend.
    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.chart.*;
    import javafx.stage.Stage;
    public class ThreeSeriesBarChart extends Application {
      @Override public void start(Stage stage) {
        final CategoryAxis xAxis = new CategoryAxis();
        xAxis.setLabel("Bars");
        final NumberAxis yAxis = new NumberAxis();
        yAxis.setLabel("Value");
        final BarChart<String, Number> bc = new BarChart<>(xAxis, yAxis);
        XYChart.Series lowSeries = new XYChart.Series();
        lowSeries.setName("Not Achieved");
        XYChart.Series medSeries = new XYChart.Series();
        medSeries.setName("Achieved");
        XYChart.Series hiSeries  = new XYChart.Series();
        hiSeries.setName("Exceeded");
        bc.setBarGap(0);
        bc.setCategoryGap(0);
        for (int i = 0; i < 10; i++) {
          final XYChart.Data<String, Number> data = new XYChart.Data("Value " + i, i);
          if (data.getYValue().intValue() > 8) {
            hiSeries.getData().add(data);
          } else if (data.getYValue().intValue() > 5) {
            medSeries.getData().add(data);
          } else {
            lowSeries.getData().add(data);
        bc.getData().setAll(lowSeries, medSeries, hiSeries);
        bc.getStylesheets().add(getClass().getResource("colored-chart.css").toExternalForm());
        stage.setScene(new Scene(bc));
        stage.show();
      public static void main(String[] args) {
        launch(args);
    import javafx.application.Application;
    import javafx.beans.value.*;
    import javafx.geometry.Pos;
    import javafx.scene.*;
    import javafx.scene.chart.*;
    import javafx.scene.control.Label;
    import javafx.scene.layout.*;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.*;
    import javafx.stage.Stage;
    public class DynamicallyColoredBarChart extends Application {
      @Override public void start(Stage stage) {
        final CategoryAxis xAxis = new CategoryAxis();
        xAxis.setLabel("Bars");
        final NumberAxis yAxis = new NumberAxis();
        yAxis.setLabel("Value");
        final BarChart<String, Number> bc = new BarChart<>(xAxis, yAxis);
        bc.setLegendVisible(false);
        XYChart.Series series1 = new XYChart.Series();
        for (int i = 0; i < 10; i++) {
          // change color of bar if value of i is >5 than red if i>8 than blue
          final XYChart.Data<String, Number> data = new XYChart.Data("Value " + i, i);
          data.nodeProperty().addListener(new ChangeListener<Node>() {
            @Override
            public void changed(ObservableValue<? extends Node> ov, Node oldNode, Node newNode) {
              if (newNode != null) {
                if (data.getYValue().intValue() > 8) {
                  newNode.setStyle("-fx-bar-fill: -fx-exceeded;");
                } else if (data.getYValue().intValue() > 5) {
                  newNode.setStyle("-fx-bar-fill: -fx-achieved;");
                } else {
                  newNode.setStyle("-fx-bar-fill: -fx-not-achieved;");
          series1.getData().add(data);
        bc.getData().add(series1);
        LevelLegend legend = new LevelLegend();
        legend.setAlignment(Pos.CENTER);
        VBox chartWithLegend = new VBox();
        chartWithLegend.getChildren().setAll(bc, legend);
        chartWithLegend.getStylesheets().add(getClass().getResource("colored-chart.css").toExternalForm());
        stage.setScene(new Scene(chartWithLegend));
        stage.show();
      class LevelLegend extends GridPane {
        LevelLegend() {
          setHgap(10);
          setVgap(10);
          addRow(0, createSymbol("-fx-exceeded"),     new Label("Exceeded"));
          addRow(1, createSymbol("-fx-achieved"),     new Label("Achieved"));
          addRow(2, createSymbol("-fx-not-achieved"), new Label("Not Achieved"));
          getStyleClass().add("level-legend");
        private Node createSymbol(String fillStyle) {
          Shape symbol = new Ellipse(10, 5, 10, 5);
          symbol.setStyle("-fx-fill: " + fillStyle);
          symbol.setStroke(Color.BLACK);
          symbol.setStrokeWidth(2);
          return symbol;
      public static void main(String[] args) { launch(args); }
    /** colored-chart.css: place in same directory as other bar chart application files and setup your build system to copy it to the output directory */
    .root {
      -fx-not-achieved: red;
      -fx-achieved:     green;
      -fx-exceeded:     blue;
    .default-color0.chart-bar { -fx-bar-fill: -fx-not-achieved; }
    .default-color1.chart-bar { -fx-bar-fill: -fx-achieved; }
    .default-color2.chart-bar { -fx-bar-fill: -fx-exceeded; }
    .level-legend {
      -fx-padding: 10;
      -fx-border-width: 2;
      -fx-background-color: rgba(211, 211, 211, 0.5);
      -fx-border-color: derive(rgba(211, 211, 211, 0.7), 10%);
    }

  • How to add a listener for enter key

    I'd like to build a chatzone applcation just like msn. The application
    has two textarea, one is for the messages sent and recieve and one is
    for the message typing area. Just like MSN, I'd like to send the text
    after the user pressed enter key. But my problem is I don't know how
    to make a key listener. I've tried jTextArea1.addKeyListener() but I don't
    know how to use it. Anyone can help me?
    Thanks in advance

    KeyListener is just an interface, so you could use:
    public class MyKeyListener implements KeyListener
       private JTextArea area = null;
       public MyKeyListener (JTextArea area)
            this.area = area;
       // Don't care about a key being pressed.
       public void keyPressed (KeyEvent e) {}
       // Don't care about a key being typed.
       public void keyTypes (KeyEvent e) {}
       // We care about the key being released.
       public void keyReleased (KeyEvent e)
           // Check what key it is.  Note sure if \n is the right one...maybe use the key codes.
           if (e.getKeyChar () == '\n')
                // The return key has been pressed and released, they really meant to press it!
                // Get the last line of the text from the text area.  This bits up to you...maybe
                // store the last location of the caret and then read from that point up
                // to the current point...
    }You can also use a DocumentListener if you are using a JTextArea but this is a little bit more complex but may be better, DocumentListeners work on telling you about more macro changes to the document...

  • How to add a listener for frame change

    hello
    Im quite new to jmf, and im writing a code which uses the webcam, but im stuck at a point where i want a listener which is called whenever the frame changes in the visualcomponent. so basically im looking for a frame changed listener to be added to the visual component instead of using a loop or a timer or something.
    i just need a method to be called constantly along the stream coming from the webcam but which is consistent with the changing of the frames.
    i would really appreciate any kind of help.
    thank you

    i thought there would be a listener or something ready to do thisThere is. It's the Rendered interface, which has a callback everytime data is received. If you want to create a custom renderer that is triggered everytime data is available, you set a processor to use your renderer and when data is available, your process command will be called. Same as an event listener...but it's very advanced stuff to implement the renderer interface.
    for example if u want to record a video ull need to capture every frame as soon as it comesNo, the video doesn't come to you a frame at a time. The video is already encoded somehow when you get it, so it's coming in as a stream just like it'll be going out to the file... It's a stream of bytes, not a stream of images... You're not digitizing here, you're transcoding.

  • How to add three batches for a single material during vendor return through

    Dear All,
    We have to sent back some stock to vendor through MBRL.This stock consist of two batches.But during MBRL i could able to enter only one batch.How can i give more batches in this screen.
    Please give the inputs.
    Thanks and regards,
    deepti

    If you are doing it with MBRL, then you have to specify a material document number.
    So the posting can only have the same info as SAP could adopt from this material document.
    You probably have to execute MBRL several times

  • How can i add multiple validations for a single input box in adf?

    hi,
    i want to add multiple validation for a single input text control in adf like number validation and its existence in database.
    MY JDEV VERSION IS 11.1.1.5.0
    pls help !!!!

    Hi,
    1.I want to validate if the value entered is pure integer
    Option 1-
    select the component and in the Property Inspector, in the "Core" category select a "Converter" format, select javax.faces.Number, if the user put a string, adf show a dialog error or message error...
    Option 2-
    or use the Regular expression:-
    http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_validateRegExp.html
    https://blogs.oracle.com/shay/entry/regular_expression_validation
    Also check this:-
    http://docs.oracle.com/cd/E15523_01/web.1111/b31973/af_validate.htm#BABHAHEI
    Option 3-
    Frank in his great book 'Oracle Fusion Developer Guide' shows a example using a javascript for input which is allowed only for numbers. You can manipulate for your requirement.
    Here is the code:
    function filterForNumbers(evt) {
        //get ADF Faces event source, InputText.js
        var inputField = evt.getSource();
        var oldValue = inputField.getValue();
        var ignoredControlKeys = new Array(AdfKeyStroke.BACKSPACE_KEY, AdfKeyStroke.TAB_KEY, AdfKeyStroke.ARROWLEFT_KEY, AdfKeyStroke.ARROWRIGHT_KEY, AdfKeyStroke.ESC_KEY, AdfKeyStroke.ENTER_KEY, AdfKeyStroke.DELETE_KEY);
        //define the key range to exclude from field input
        var minNumberKeyCode = 48;
        var maxNumberKeyCode = 57;
        var minNumberPadKeyCode = 96;
        var maxNumberPadKeyCode = 105;
        //key pressed by the user
        var keyCodePressed = evt.getKeyCode();
        //if it is a control key, don't suppress it
        var ignoreKey = false;
        for (keyPos in ignoredControlKeys) {
            if (keyCodePressed == ignoredControlKeys[keyPos]) {
                ignoreKey = true;
                break;
        //return if key should be ignored
        if (ignoreKey == true) {
            return true;
        //filter keyboard input
        if (keyCodePressed < minNumberKeyCode || keyCodePressed > maxNumberPadKeyCode) {
            //set value back to previous value
            inputField.setValue(oldValue);
            //no need for the event to propagate to the server, so cancel
            //it
            evt.cancel();
            return true;
        if (keyCodePressed > maxNumberKeyCode && keyCodePressed < minNumberPadKeyCode) {
            //set value back to previous value
            inputField.setValue(oldValue);
            evt.cancel();
            return true;
    2.I want to check if the value exists in my respective DB You must be having EO or VO if you want to validate with database in that case use the solution suggested by Timo.
    Thanks
    --NavinK                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to set Compatibility Mode for a single site in ie10

    This question was originally posted on the Answers forum -
    http://answers.microsoft.com/en-us/ie/forum/ie10-windows_7/how-to-set-compatibility-mode-for-a-single-site-in/187152e3-142a-4d96-8d1b-af82ef571eec
    I am having problem with getting ie10 to set ie9 compatibility for a single site (sharepoint.contoso.com).
    When I add this website in Compatibility View Settings (Alt > Tools > Compatibility View Settings > 'Add this Website') it adds the domain 'contoso.com' and not the individual website (sharepoint.contoso.com).
    This cause other sites (www.contoso.com) to be configured to use compatibility mode. Because this is a separate site (different web server) to the site sharepoint.contoso.com (sharepoint 2010 server) we need different compatibility settings.
    Using a different example to explain the issue -
    Microsoft has three websites that are different websites created by different developers written in different programming languages and they only work with certain browsers.
    microsoft.com (Website1 created by Developer1) - compatible with ie8/ie9/ie10
    msdn.microsoft.com (Website2 created by Developer2) - compatible with ie8/ie9
    technet.microsoft.com (Website3 website created by Developer3) - compatible only with ie10
    The only thing the three website share is the URL contains 'microsoft.com'.
    Marking 'msdn.microsoft.com' to run in compatibility mode affects the other 2 websites - mainly technet.microsoft.com which will not work now since it only runs in pure ie10 mode. 
    Should you be able to add an individual site to the compatibility list instead of all sites that have  .microsoft.com in the URL? Am I missing a simple setting in the ie10?
    As a workaround I am using the F12 Developer Tools to set the Browser Mode which temporary sets the compatibility mode. However this is not a nice solution to the end users at our organisation. 

    problem is not solved for non corporate environments...
    You could start your own thread.  Then if you got that answer and it was marked Answered you would have the ability to unmark it.  The OP of this one seems satisfied.  Also note that this is TechNet.  Consumers can get help on Answers
    forums.
    Robert Aldwinckle
    Oh! I wrote it wrong: I should have said: This is not solved for NON-AD environments. No demands what so ever to use Window 7/8 professional in a small corporation or on a big corporation with Island of smaller departments for example offshore.
    The problem is that the thread is not "Answered" by the OP, its is marked answered by a moderator (and same moderator that did the answer) so no way of telling if the OP is satisfied.
    But you are right in the fact that I am almost kidnapping the thread. But a complete answer would benefit all in this case I would presume.
    Regards
    /Aldus

  • How to add indian english for siri?

    how to add indian english for siri... siri no use for indian user...

    You cannot, it is something only Apple can do.
    The phone merely listens to the commands, digitizes into some proprietary format and sends it to Apple's servers, who do the heavy lifting of interpreting what you want. So you can't hack the language into the phone.

  • How to know which leaf node i click and how to add a listener to each node?

    hi! hello to all members, i have a problem i know how to create a listener, but i dont know how to add a listener to each leaf node. here is the scenario i want to do, i have a JTree where theres a topic that you can select on each leaf node, so when the user click the specific topic it will open another JFrame,which i dont know how to do it also, that its! the next problem will be how do i know which leaf node i select, so that i can open a right topic before the JFrame will open?please, i am very need this to solve quickly as possible. thanks again to all members.

    What you have to do is to add a mouse listener on your JTree. Try something like this:
    tree.addMouseListener(new java.awt.event.MouseAdapter() {
             public void mouseReleased(MouseEvent e) {
                tree_mouseReleased(e);
    private void tree_mouseReleased(MouseEvent e) {
          TreePath selPath = tree.getSelectionPath();
          // Check If the click is the Right Click
          if (e.isPopupTrigger() == true) {
          // This is your right Click
           else {
                     // This is your Left Click
    }Your other problem: Set the userObject on nodes and on left click compare it with your object, if it matches, display the appropriate file. Alternatively, if your nodes are unique, you can match the names to open the file.
    Hope this Helps
    Regard
    Raheel

  • How to create a Platinum,Gold and Silver Customer and how to set different price for a single material based on customer?

    Hi All,
    How to create a Platinum,Gold and Silver Customer and how to set different price for a single material based on customer?
    Assume Material is Pen.
    While creating Sales Order in VA01 how to bring different price for the same material for Platinum,Gold and Silver Customers.
    Kindly help me out.
    Thanks,
    Renjith Jose

    A good place to start is http://www.javaworld.com/javaworld/javatips/jw-javatip34.html
    Also, do a search in this forum on HttpURLConnection. That class allows you to use POST method to send form data to a web server.
    "Hidden" variables are only hidden in HTML. The HTTP that gets POSTed to the web server doesn't distinguish between hidden and not hidden. That is, the content you would write to the HttpURLConnection.getOutputStream() would be something like:
    hidden=1&submit=ok(Of course, the variable names would depend on what the web server was expecting from the form.)
    Also, be sure to set the Content-Type request parameter to "application/x-www-form-urlencoded"

  • HOW TO: Add /manipulate columns for a GridControl

    HOW TO: Add /manipulate columns for a GridControl when the columns (attributes) are from different entity objects.
    This HOWTO describes the basic steps of using attributes from different entity objects for a GridControl.
    One way you can create a GridControl which contain attributes from different entity objects is to create a view object and base it on the entity objects which contain
    the desired attributes.
    Here are the basic steps:
    1.Create a new view object (or use an existing view object) by selecting File>New from the menu, clicking the Business Components tab and double-clicking
    on the View Object icon.
    2.In the View Object wizard change the name to something meaningful.
    3.Select the entity objects you will base your view object on.
    4.Nivigate to the attribute screen and select the attributes you would like to include in your view object from each entity object. At this point you can also create
    a new attribute by clicking the "New" button. The new attribute can be a concatenation of other attributes, derived from a calculation etc.
    5.In the query panel of the View Object wizard, click "Expert mode" and enter a query statement. You write complex queries such as decoding a set of attribute
    values.
    6.Add your newly to your newly created view object to the application module by double-clicking on the application module in the navigation pane and selecting
    your view object from the list.
    7.Create a new row set.
    8.Bind row set to a query by editing their queryinfo property and selecting your view object and its attributes from the queryInfo pane.
    9.Create a GridControl and bind it to the row set by editing the dataItemName property of the GridControl. Since the GridControl is bound at the row set level
    all of the related attributes are automatically added.
    null

    Michael,
    Are you intending this as a commercial solution or a work around?
    To take an existing equivalent, one would build a view in the database tailored for each grid in an Oracle Forms application. Or a separate query layered over tables for each form/grid in a Delphi or Access application? Even if it is ninety nine percent the same over half a dozen forms/grids?
    And now you've added a whole slew of "slightly different" rowSetInfos to maintain.
    So if you wanted to add a column that needs to appear everywhere... you've just increased the workload multi-fold?
    That would be a management nightmare, wouldn't it? Not to mention yet more performance cost and a slower system?
    Hmmmm..... I'm not sure I like where this is headed... someone needs to do some convincing...
    null

  • Hi All how to add new payscale  for an employee in sap hr-abap,its urgent

    Hi All ,
    how to add new payscale for an employee  in sap hr-abap,its urgent.
    Message was edited by:
            bharat kumar
    Message was edited by:
            bharat kumar

    Hi
    If that field which you wants to add is available in one of the structures like EKKO,EKPO then you can add that field just beside the other fields
    If that field is not there in the any of the structures then you can define a variable using define command
    /: DEFINE  &VAR&
    / &VAR&  = <some value>
    or you can write subroutines to fetch the data from outside tables and can use those fields data in the script
    <b>Reward points for useful Answers</b>
    Regards
    Anji

Maybe you are looking for

  • Disk Permissions constantly need Repair

    Hi, I've just upgraded to 10.6.5 and noticed that each time I log in, my disk permissions need repair. I've updated everything, but still seem to have permissions problems. Any help would be appreciated. These are the errors. Many thanks! Permissions

  • "This email address is already in use" for apple ID. I don't have another account. How can I change it?

    I have read through other responses - from back in November... Tried everything.  Must have at one point tried to use new email for apple id - but it won't let me do it now.  Frustrating!,,

  • EDI Invoice with multiple banks

    Hi all,        I have outbound EDI invoice 810 where there are several banks listed in the Idoc file. The bank info is listed in segment E1EDK28 in Idoc basic type  INVOIC02. I have 6 of the E1EDK28 segments and the first segment is not the correct b

  • Update to sdk 3.3 - no flash.* package

    Updating to sdk 3.3 using eclipse with flex plugin results in losing the flash package code completion. The application still compiles and I don't have errors, but the flex builder plugin doesn't e.g. code-complete and auto-import flash.events.EventD

  • My trackpad will work sporadically and I'm wondering how to fix this

    My trackpad will not work sometimes and I'm wondering how to fix it? How can it be repaired? I was also wondering the steps to take to send it in to get a new trackpad