SlideShare a Scribd company logo
1 of 10
Download to read offline
How do I make my JTable non editable?
import java.awt.*;
import javax.swing.table.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.nio.*;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class SwingDemo implements ActionListener, KeyListener
{
JLabel search, output;
JFrame viewer;
JTable table = new JTable(new DefaultTableModel(null, new Object []{"Row ID", "First
Name", "Last Name", "EMPLID", "GPA", "Venus Login"}));
JFrame viewerAdd;
DefaultTableModel model = (DefaultTableModel) table.getModel();
JTextField first = new JTextField(20);
JTextField last = new JTextField(20);
JTextField emplid = new JTextField(20);
JTextField gpa = new JTextField(20);
JTextField venus = new JTextField(10);
String Venus;
public static int rowCount = 1;
public final static int LOAD = 0;
public final static int SAVE = 1;
public SwingDemo()
{
//Creates Java Frame
viewer = new JFrame("Final Project");
viewer.setSize(570, 650);
viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
viewer.setLayout(new FlowLayout());
viewer.setLocationRelativeTo(viewer);
//Creates Drop Down Menu
String[] option = { "Row ID", "First Name", "Last Name", "EMPLID", "GPA", "Venus
Login" };
JComboBox options = new JComboBox(option);
options.setSelectedIndex(0);
//Creates Button and Labels
search = new JLabel("Search by: ");
JButton addButton = new JButton("Add");
JButton deleteButton = new JButton("Delete");
JButton exportButton = new JButton("Export Data");
//Creates JTable
JTextField textBox = new JTextField(20);
table = new JTable(model);
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
//Creates Menu Bar
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu helpMenu = new JMenu("Help");
menuBar.add(fileMenu);
menuBar.add(helpMenu);
JMenuItem openAction = new JMenuItem("Open");
JMenuItem exitAction = new JMenuItem("Exit");
JMenuItem exportAction = new JMenuItem("Export");
JMenuItem aboutAction = new JMenuItem("About");
fileMenu.add(openAction);
fileMenu.add(exportAction);
fileMenu.add(exitAction);
helpMenu.add(aboutAction);
//fileChooser.setDialogTitle("Choose a file");
//ActionListener
openAction.addActionListener(this);
exitAction.addActionListener(this);
aboutAction.addActionListener(this);
addButton.addActionListener(this);
//Action Events
//Adds Elements to Java Frame
viewer.setJMenuBar(menuBar);
viewer.add(search);
viewer.add(options);
viewer.add(textBox);
viewer.add(addButton);
viewer.add(deleteButton);
viewer.add(scrollPane);
viewer.add(exportButton);
viewer.setVisible(true);
}
public void addUser()
{
JButton OK = new JButton("OK");
JButton CANCEL = new JButton("CANCEL");
//JTextField
//Strings
JLabel firstName = new JLabel("First Name");
JLabel lastName = new JLabel("Last Name");
JLabel EMPLID = new JLabel("EMPLID");
JLabel GPA = new JLabel("GPA");
JLabel venusLogin = new JLabel("Venus Login");
//ActionListener
first.addActionListener(this);
last.addActionListener(this);
emplid.addActionListener(this);
gpa.addActionListener(this);
first.addKeyListener(this);
last.addKeyListener(this);
emplid.addKeyListener(this);
viewerAdd = new JFrame("Add User");
viewerAdd.setSize(300, 200);
viewerAdd.setDefaultCloseOperation(viewerAdd.HIDE_ON_CLOSE);
viewerAdd.setLayout(new GridLayout(6,2));
viewerAdd.setLocationRelativeTo(viewerAdd);
viewerAdd.add(firstName);
viewerAdd.add(first);
viewerAdd.add(lastName);
viewerAdd.add(last);
viewerAdd.add(EMPLID);
viewerAdd.add(emplid);
viewerAdd.add(GPA);
viewerAdd.add(gpa);
viewerAdd.add(venusLogin);
viewerAdd.add(venus);
viewerAdd.add(OK);
viewerAdd.add(CANCEL);
OK.addActionListener(this);
CANCEL.addActionListener(this);
venus.setEditable(false);
viewerAdd.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) throws NumberFormatException
{
switch(e.getActionCommand())
{
case "Exit":
System.exit(0);
break;
case "Open":
FileDialog fileChooser = new FileDialog(viewerAdd,"Select file",FileDialog.LOAD);
fileChooser.setVisible(true);
JFileChooser a = new JFileChooser(fileChooser.getFile());
File[] file;
file = fileChooser.getFiles();
if(fileChooser.getFile() != null)
{
try
{
BufferedReader br = new BufferedReader(new FileReader(file[0]));
String line;
while ((line = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line, "," +" ");
String f = st.nextToken();
String l = st.nextToken();
String em = st.nextToken();
String g = st.nextToken();
String v = st.nextToken();
model.addRow(new Object[]{rowCount++,f, l, em, g, v});
}
}
catch (FileNotFoundException ex)
{
System.out.println("o");
}
catch (IOException e1)
{
JOptionPane.showMessageDialog(fileChooser, "There was an IO Exception that was
caught. Error: "+ e1.getMessage(), null, JOptionPane.ERROR_MESSAGE);
e1.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(null, "File Not Selected", null,
JOptionPane.ERROR_MESSAGE);
}
break;
case "About":
JOptionPane.showMessageDialog(viewer, "This is an App made by ");
break;
case "Add":
addUser();
break;
case "OK":
int userAction1 = JOptionPane.showConfirmDialog(null, "Are You Sure You Want To Insert
this Record?");
int number;
double number1;
boolean emp, ga = false;
if(userAction1 == JOptionPane.YES_OPTION)
{
String firstName = first.getText();
String lastName = last.getText();
String Emplid = emplid.getText();
String Gpa = gpa.getText();
if (firstName.length() < 2)
JOptionPane.showMessageDialog(null, "First Name must contain at least 2 characters",
null, JOptionPane.ERROR_MESSAGE);
else if (lastName.length() < 2)
JOptionPane.showMessageDialog(null, "Last Name must contain at least 2 characters",
null, JOptionPane.ERROR_MESSAGE);
else if (Emplid.length()!=8)
JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers", null,
JOptionPane.ERROR_MESSAGE);
try
{
number = Integer.parseInt(Emplid);
try
{
number1 = Double.parseDouble(Gpa);
if(number1 < 0 || number1 > 4)
JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null,
JOptionPane.ERROR_MESSAGE);
else
ga = true;
}
catch (Exception s)
{
JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null,
JOptionPane.ERROR_MESSAGE);
}
}
catch (Exception s)
{
JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers only", null,
JOptionPane.ERROR_MESSAGE);
}
if (ga == true)
{
model.addRow(new Object[]{rowCount++,firstName, lastName, Emplid, Gpa, Venus});
viewerAdd.setVisible(false);
first = new JTextField(20);
last = new JTextField(20);
emplid = new JTextField(20);
gpa = new JTextField(20);
venus = new JTextField(10);
}
}
break;
case "CANCEL":
viewerAdd.setVisible(false);
break;
}
}
@Override
public void keyTyped(KeyEvent e)
{
try
{
venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub
string(4,8));
}
catch(Exception s)
{
}
Venus = venus.getText();
}
@Override
public void keyPressed(KeyEvent e)
{
try
{
venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub
string(4,8));
}
catch(Exception s)
{
}
Venus = venus.getText();
}
@Override
public void keyReleased(KeyEvent e)
{
try
{
venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub
string(4,8));
}
catch(Exception s)
{
}
Venus = venus.getText();
}
}
Solution
step 1:Go to the Navigation Pane, expand JScrollPane option
step 2:In JSCROLLPne, right-click on JTable and Select Customize Code as shown below:
step 3:On the code customizer option, choose custom property in the second drop down
step 4: Insert the code written below ,before the last bracket);code is given below
step5:{public boolean isCellEditable(int row, int column){return false;}}

More Related Content

Similar to How do I make my JTable non editableimport java.awt.; import j.pdf

I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdffashionfolionr
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfanushkaent7
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfamrishinda
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfJUSTSTYLISH3B2MOHALI
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfarvindarora20042013
 
Registro de venta
Registro de ventaRegistro de venta
Registro de ventalupe ga
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfvenkt12345
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
Ejemplo radio
Ejemplo radioEjemplo radio
Ejemplo radiolupe ga
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
import javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfimport javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfADITIEYEWEAR
 
Soundreader.classpathSoundreader.project Soundre.docx
Soundreader.classpathSoundreader.project  Soundre.docxSoundreader.classpathSoundreader.project  Soundre.docx
Soundreader.classpathSoundreader.project Soundre.docxwhitneyleman54422
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfatulkapoor33
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 

Similar to How do I make my JTable non editableimport java.awt.; import j.pdf (20)

I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
 
Notepad
NotepadNotepad
Notepad
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdf
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdf
 
Registro de venta
Registro de ventaRegistro de venta
Registro de venta
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Easy Button
Easy ButtonEasy Button
Easy Button
 
Ejemplo radio
Ejemplo radioEjemplo radio
Ejemplo radio
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
import javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfimport javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdf
 
Java Assignment Help
Java Assignment HelpJava Assignment Help
Java Assignment Help
 
Maze
MazeMaze
Maze
 
Soundreader.classpathSoundreader.project Soundre.docx
Soundreader.classpathSoundreader.project  Soundre.docxSoundreader.classpathSoundreader.project  Soundre.docx
Soundreader.classpathSoundreader.project Soundre.docx
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 

More from forwardcom41

Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfforwardcom41
 
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfforwardcom41
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfforwardcom41
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfforwardcom41
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfforwardcom41
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfforwardcom41
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfforwardcom41
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfforwardcom41
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfforwardcom41
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfforwardcom41
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfforwardcom41
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfforwardcom41
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfforwardcom41
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfforwardcom41
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfforwardcom41
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfforwardcom41
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfforwardcom41
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfforwardcom41
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfforwardcom41
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdfforwardcom41
 

More from forwardcom41 (20)

Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
 
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdf
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdf
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdf
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdf
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdf
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdf
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdf
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdf
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdf
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdf
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdf
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdf
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdf
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdf
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 

How do I make my JTable non editableimport java.awt.; import j.pdf

  • 1. How do I make my JTable non editable? import java.awt.*; import javax.swing.table.*; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; import java.awt.event.*; import java.io.*; import javax.swing.*; import java.nio.*; import java.nio.charset.Charset; import java.nio.file.*; import java.awt.Desktop; import java.io.File; import java.io.IOException; import java.util.Scanner; import java.util.StringTokenizer; public class SwingDemo implements ActionListener, KeyListener { JLabel search, output; JFrame viewer; JTable table = new JTable(new DefaultTableModel(null, new Object []{"Row ID", "First Name", "Last Name", "EMPLID", "GPA", "Venus Login"})); JFrame viewerAdd; DefaultTableModel model = (DefaultTableModel) table.getModel(); JTextField first = new JTextField(20); JTextField last = new JTextField(20); JTextField emplid = new JTextField(20); JTextField gpa = new JTextField(20); JTextField venus = new JTextField(10); String Venus; public static int rowCount = 1; public final static int LOAD = 0;
  • 2. public final static int SAVE = 1; public SwingDemo() { //Creates Java Frame viewer = new JFrame("Final Project"); viewer.setSize(570, 650); viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); viewer.setLayout(new FlowLayout()); viewer.setLocationRelativeTo(viewer); //Creates Drop Down Menu String[] option = { "Row ID", "First Name", "Last Name", "EMPLID", "GPA", "Venus Login" }; JComboBox options = new JComboBox(option); options.setSelectedIndex(0); //Creates Button and Labels search = new JLabel("Search by: "); JButton addButton = new JButton("Add"); JButton deleteButton = new JButton("Delete"); JButton exportButton = new JButton("Export Data"); //Creates JTable JTextField textBox = new JTextField(20); table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); //Creates Menu Bar JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu helpMenu = new JMenu("Help"); menuBar.add(fileMenu); menuBar.add(helpMenu);
  • 3. JMenuItem openAction = new JMenuItem("Open"); JMenuItem exitAction = new JMenuItem("Exit"); JMenuItem exportAction = new JMenuItem("Export"); JMenuItem aboutAction = new JMenuItem("About"); fileMenu.add(openAction); fileMenu.add(exportAction); fileMenu.add(exitAction); helpMenu.add(aboutAction); //fileChooser.setDialogTitle("Choose a file"); //ActionListener openAction.addActionListener(this); exitAction.addActionListener(this); aboutAction.addActionListener(this); addButton.addActionListener(this); //Action Events //Adds Elements to Java Frame viewer.setJMenuBar(menuBar); viewer.add(search); viewer.add(options); viewer.add(textBox); viewer.add(addButton); viewer.add(deleteButton); viewer.add(scrollPane); viewer.add(exportButton); viewer.setVisible(true); } public void addUser() { JButton OK = new JButton("OK"); JButton CANCEL = new JButton("CANCEL"); //JTextField
  • 4. //Strings JLabel firstName = new JLabel("First Name"); JLabel lastName = new JLabel("Last Name"); JLabel EMPLID = new JLabel("EMPLID"); JLabel GPA = new JLabel("GPA"); JLabel venusLogin = new JLabel("Venus Login"); //ActionListener first.addActionListener(this); last.addActionListener(this); emplid.addActionListener(this); gpa.addActionListener(this); first.addKeyListener(this); last.addKeyListener(this); emplid.addKeyListener(this); viewerAdd = new JFrame("Add User"); viewerAdd.setSize(300, 200); viewerAdd.setDefaultCloseOperation(viewerAdd.HIDE_ON_CLOSE); viewerAdd.setLayout(new GridLayout(6,2)); viewerAdd.setLocationRelativeTo(viewerAdd); viewerAdd.add(firstName); viewerAdd.add(first); viewerAdd.add(lastName); viewerAdd.add(last); viewerAdd.add(EMPLID); viewerAdd.add(emplid); viewerAdd.add(GPA); viewerAdd.add(gpa); viewerAdd.add(venusLogin); viewerAdd.add(venus); viewerAdd.add(OK); viewerAdd.add(CANCEL); OK.addActionListener(this); CANCEL.addActionListener(this);
  • 5. venus.setEditable(false); viewerAdd.setVisible(true); } @Override public void actionPerformed(ActionEvent e) throws NumberFormatException { switch(e.getActionCommand()) { case "Exit": System.exit(0); break; case "Open": FileDialog fileChooser = new FileDialog(viewerAdd,"Select file",FileDialog.LOAD); fileChooser.setVisible(true); JFileChooser a = new JFileChooser(fileChooser.getFile()); File[] file; file = fileChooser.getFiles(); if(fileChooser.getFile() != null) { try { BufferedReader br = new BufferedReader(new FileReader(file[0])); String line; while ((line = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(line, "," +" "); String f = st.nextToken(); String l = st.nextToken(); String em = st.nextToken();
  • 6. String g = st.nextToken(); String v = st.nextToken(); model.addRow(new Object[]{rowCount++,f, l, em, g, v}); } } catch (FileNotFoundException ex) { System.out.println("o"); } catch (IOException e1) { JOptionPane.showMessageDialog(fileChooser, "There was an IO Exception that was caught. Error: "+ e1.getMessage(), null, JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "File Not Selected", null, JOptionPane.ERROR_MESSAGE); } break; case "About": JOptionPane.showMessageDialog(viewer, "This is an App made by "); break; case "Add": addUser(); break; case "OK": int userAction1 = JOptionPane.showConfirmDialog(null, "Are You Sure You Want To Insert this Record?"); int number; double number1;
  • 7. boolean emp, ga = false; if(userAction1 == JOptionPane.YES_OPTION) { String firstName = first.getText(); String lastName = last.getText(); String Emplid = emplid.getText(); String Gpa = gpa.getText(); if (firstName.length() < 2) JOptionPane.showMessageDialog(null, "First Name must contain at least 2 characters", null, JOptionPane.ERROR_MESSAGE); else if (lastName.length() < 2) JOptionPane.showMessageDialog(null, "Last Name must contain at least 2 characters", null, JOptionPane.ERROR_MESSAGE); else if (Emplid.length()!=8) JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers", null, JOptionPane.ERROR_MESSAGE); try { number = Integer.parseInt(Emplid); try { number1 = Double.parseDouble(Gpa); if(number1 < 0 || number1 > 4) JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null, JOptionPane.ERROR_MESSAGE); else ga = true; } catch (Exception s) { JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null, JOptionPane.ERROR_MESSAGE); } }
  • 8. catch (Exception s) { JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers only", null, JOptionPane.ERROR_MESSAGE); } if (ga == true) { model.addRow(new Object[]{rowCount++,firstName, lastName, Emplid, Gpa, Venus}); viewerAdd.setVisible(false); first = new JTextField(20); last = new JTextField(20); emplid = new JTextField(20); gpa = new JTextField(20); venus = new JTextField(10); } } break; case "CANCEL": viewerAdd.setVisible(false); break; } } @Override public void keyTyped(KeyEvent e) { try { venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub string(4,8)); }
  • 9. catch(Exception s) { } Venus = venus.getText(); } @Override public void keyPressed(KeyEvent e) { try { venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub string(4,8)); } catch(Exception s) { } Venus = venus.getText(); } @Override public void keyReleased(KeyEvent e) { try { venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub string(4,8)); } catch(Exception s) { } Venus = venus.getText();
  • 10. } } Solution step 1:Go to the Navigation Pane, expand JScrollPane option step 2:In JSCROLLPne, right-click on JTable and Select Customize Code as shown below: step 3:On the code customizer option, choose custom property in the second drop down step 4: Insert the code written below ,before the last bracket);code is given below step5:{public boolean isCellEditable(int row, int column){return false;}}