How to display value in combobox and save its id into database - java

I have a combobox that the value is shown instead of Id. id should be then insert into a database. I added a listener to combobox to get the Id. By sysout I can see but how could I insert into database????
here is the code:
public void comboboxpersonneldata() {
comboboxpersonnellist = FXCollections.observableArrayList();
handler = new DBHandler();
connection = handler.getConnection();
try {
rs = connection.createStatement().executeQuery("SELECT num_personnel,nom_personnel FROM personnel");
while (rs.next()) {
// comboboxpersonnellist.add(rs.getInt(1));
comboboxpersonnellist.addAll(new comboboxPersonnel(rs.getInt(1), rs.getString(2)));
}
combopersonnel.setItems(comboboxpersonnellist);
combopersonnel.valueProperty().addListener((obs, oldval, newval) -> {
if (newval != null) {
System.out.println(newval.getNum_personnel());
}
});
} catch (SQLException e) {
e.printStackTrace();
}
try {
rs.close();
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
and the model class:
public class comboboxPersonnel {
int num_personnel;
String name_personnel;
public comboboxPersonnel(int num_personnel, String name_personnel) {
this.num_personnel = num_personnel;
this.name_personnel = name_personnel;
}
public int getNum_personnel() {
return num_personnel;
}
public String getName_personnel() {
return name_personnel;
}
#Override
public String toString() {
return name_personnel;
}
}

Related

Socket blocking client when sending image

So I'm making a simple chat where I'm sending content in the form of objects, in this case my problem is that when I'm sending and Image it just blocking my Client!, here's my shortened code.
I've isolated it mostly to the code below, as I've tested the rest and worked fine, I've also tried debugging this but I just can't seem to find the problem
Image
package com.example.mtc.Packets;
import java.io.Serializable;
public class Image extends Message implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3188407715959746920L;
private byte[] content;
private String type;
public Image(byte[] content,String type, int sourceID,int destinationID,String sourceUsername) {
super(destinationID,sourceID,sourceUsername);
this.content = content;
this.type = "." + type;
}
public byte[] getContent() {
return content;
}
public String getType() {
return type;
}
}
ClientReaderThread:
while (true) {
try {
inputData = in.readObject();
if (inputData.getClass().getName().equals("com.example.mtc.Packets.Image")) {
Image imagePacket = (Image) inputData;
byte[] imageContent = imagePacket.getContent();
ImageIcon imageIcon = new ImageIcon(imageContent);
imageIcon.setImage(imageIcon.getImage().getScaledInstance(300, 300, java.awt.Image.SCALE_DEFAULT));
if (imagePacket.getDestinationID() == 0) {
if (Cliente.selectedChat == 0) {
Style style = chatCard.doc.addStyle("StyleName", null);
StyleConstants.setIcon(style, imageIcon);
chatCard.doc.insertString(chatCard.doc.getLength(), "ignored text\n", style);
chatCard.textPane.setCaretPosition(chatCard.textPane.getDocument().getLength());
Cliente.gui.revalidate();
}
} else if (imagePacket.getSourceID() == Cliente.selectedChat
|| imagePacket.getSourceID() == Cliente.getUserID()) {
Style style = chatCard.doc.addStyle("StyleName", null);
StyleConstants.setIcon(style, imageIcon);
chatCard.doc.insertString(chatCard.doc.getLength(), "ignored text\n", style);
chatCard.textPane.setCaretPosition(chatCard.textPane.getDocument().getLength());
Cliente.gui.revalidate();
}
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(Cliente.gui, "Couldn't connect to Server!", "Error",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Server Listener
private void Listener() {
// TODO Auto-generated method stub
while (connected) {
inputData = readObject();
if (inputData != null) {
if (inputData.getClass().getName().equals("com.example.mtc.Packets.Image")) {
Image imagePacket = (Image) inputData;
byte[] imageContent = imagePacket.getContent();
ImageIcon imageIcon = new ImageIcon(imageContent);
imageIcon.setImage(imageIcon.getImage().getScaledInstance(300, 300,
java.awt.Image.SCALE_DEFAULT));
imageIcon.getImage().flush();
BufferedImage bi = new BufferedImage(
imageIcon.getIconWidth(),
imageIcon.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
// paint the Icon to the BufferedImage.
imageIcon.paintIcon(null, g, 0,0);
g.dispose();
try {
File imageFile = File.createTempFile("image", imagePacket.getType(),
new File("./serverImages/"));
insertLog(imageFile.getAbsolutePath(), imagePacket.getDestinationID(), true);
new Thread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
try {
Files.write(imageFile.toPath(), imageContent);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (imagePacket.getDestinationID() == 0) {
synchronized (Server.Threads) {
for (ClientHandler t : Server.Threads) {
if (!idExistsInBlockedList(t.getUserID(), userID)) {
t.sendObject(imagePacket);
}
}
}
} else {
synchronized (Server.Threads) {
for (ClientHandler t : Server.Threads) {
if (!idExistsInBlockedList(t.getUserID(), userID)) {
if (t.getUserID() == imagePacket.getDestinationID()) {
t.sendObject(imagePacket);
}
}
}
sendObject(imagePacket);
}
}
}
}
}
}
Managed to solve it by using SwingUtilities.invokeLater(), as advised by R.L.M

Eclipse RCP system tray IllegalArgumentException

This code used to work with Eclipse Kepler. But the developer that wrote it is gone and it is no longer working with an upgrade to Neon plugins. I am getting this exception:
Caused by: org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.IllegalArgumentException: Argument cannot be null)
at org.eclipse.swt.SWT.error(SWT.java:4533)
at org.eclipse.swt.SWT.error(SWT.java:4448)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4536)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4154)
at com.example.server.commons.SysTrayThread.localRun(SysTrayThread.java:141)
at com.example.server.commons.SysTrayThread$2.run(SysTrayThread.java:87)
With this code:
private static final String SYSTEM_BUNDLE_ID = "org.eclipse.osgi"; //$NON-NLS-1$
private volatile boolean working = true;
private final Bundle bundle;
private final String logoPath;
private Display display;
public SysTrayThread (final Bundle bundle, final String logoPath) {
this.bundle = bundle;
this.logoPath = logoPath;
}
#Override
public void run() {
if(System.getProperty("os.name").equals("Mac OS X")) {
Class<?> comAppleConcurrentDispatch = null;
try {
comAppleConcurrentDispatch = Class.forName("com.apple.concurrent.Dispatch");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Method getInstance = null;
Object dispatchInstance = null;
Method getNonBlockingMainQueueExecutor = null;
Executor executor = null;
try {
getInstance = comAppleConcurrentDispatch.getMethod("getInstance", (Class<?>[]) null);
dispatchInstance = getInstance.invoke(null, (Object[]) null);
getNonBlockingMainQueueExecutor = dispatchInstance.getClass().getMethod("getNonBlockingMainQueueExecutor",(Class<?>[]) null);
executor = (Executor) getNonBlockingMainQueueExecutor.invoke(dispatchInstance, (Object[]) null);
executor.execute(new Runnable() {
public void run() {
try {
localRun();
} catch(Throwable t) {
}
}
}
);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
localRun();
}
});
}
}
public void localRun()
{
try {
SysTrayThread.this.display = Display.getDefault();
} catch (org.eclipse.swt.SWTError ex) {
return;
}
URL url = SysTrayThread.this.bundle.getEntry(SysTrayThread.this.logoPath);
try {
Image image = null;
Shell shell = new Shell(SysTrayThread.this.display);
InputStream stream = url.openStream();
try {
image = new Image(SysTrayThread.this.display, new ImageData(stream));
} finally {
stream.close();
}
final Menu menu = new Menu(shell, SWT.POP_UP);
MenuItem exitMenuItem = new MenuItem(menu, SWT.PUSH);
exitMenuItem.setText(Messages.SHUTDOWN_MENU_ITEM);
exitMenuItem.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent event) {
Bundle bundle = Platform.getBundle(SysTrayThread.SYSTEM_BUNDLE_ID);
try {
bundle.stop();
} catch (BundleException ex) {
throw new RuntimeException(ex);
}
}
});
Tray tray = SysTrayThread.this.display.getSystemTray();
TrayItem trayItem = new TrayItem(tray, SWT.NONE);
trayItem.addListener(SWT.MenuDetect, new Listener() {
#Override
public void handleEvent(final Event event) {
menu.setVisible(true);
}
});
trayItem.setImage(image);
while (SysTrayThread.this.working && !shell.isDisposed()) {
if (!SysTrayThread.this.display.readAndDispatch()) { // line 141
SysTrayThread.this.display.sleep();
}
}
tray.dispose();
image.dispose();
if (!shell.isDisposed()) {
shell.dispose();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
public void setWorking(final boolean working) {
if (this.display != null) {
this.display.syncExec(new Runnable() {
#Override
public void run() {
SysTrayThread.this.display.close();
}
});
}
this.working = working;
}
I had a look for RCP specific information on this problem, but the answers relate to setting an SWT element to null. As you can see I am not setting a value, just calling readAndDispatch().
Any ideas?

Elastic Search : cannot write a field name expecting a value

Okay what I am trying to achieve here is parsing a json string and separating its fields and assigning them to variables. Next I am creating a builder to send data to the elastic for indexing. But I am getting this error which is really bugging me. I am unable to move forward.
for (int i = 0; i < jsonarray.length(); i++) {
try {
obj = jsonarray.getJSONObject(i);
System.out.println(obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
try {
type = obj.getString("type");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println("Values for select");
try {
JSONArray jContent = (JSONArray) obj.get("values");
for (int iterate = 0; iterate < jContent.length(); iterate++) {
JSONObject inner = jContent.getJSONObject(iterate);
String inner_label = (String) inner.get("label");
String val = (String) inner.get("value");
boolean sel;
try {
sel = (boolean) inner.get("selected");
} catch (JSONException j) {
sel = false;
}
builder.startObject("Extras").field("inner_lab", inner_label).field("inner_value", val).field("Selected", sel).endObject();
}
} catch (JSONException e) {
}
try {
label = obj.getString("label");
} catch (JSONException e) {
e.printStackTrace();
}
try {
access = obj.getBoolean("access");
} catch (JSONException e) {
access = false;
}
try {
role = obj.getString("role");
} catch (JSONException e) {
role = null;
}
try {
subtype = obj.getString("subtype");
} catch (JSONException e) {
subtype = null;
}
try {
maxlength = obj.getString("maxlength");
} catch (JSONException e) {
maxlength = null;
}
try {
name = obj.getString("name");
} catch (JSONException e) {
name = null;
}
try {
description = obj.getString("description");
} catch (JSONException e) {
description = null;
}
try {
classname = obj.getString("className");
} catch (JSONException e) {
classname = null;
}
try {
placeholder = obj.getString("placeholder");
} catch (JSONException e) {
placeholder = null;
}
try {
value = obj.getString("value");
} catch (JSONException e) {
value = null;
}
try {
required = obj.getBoolean("required");
} catch (JSONException e) {
required = false;
}
try {
toggle = obj.getBoolean("toggle");
} catch (JSONException e) {
toggle = false;
}
try {
inline = obj.getBoolean("inline");
} catch (JSONException e) {
inline = false;
}
try {
enableother = obj.getBoolean("other");
} catch (JSONException e) {
enableother = false;
}
try {
multipleFiles = obj.getBoolean("multiple");
} catch (JSONException e) {
multipleFiles = false;
}
try {
style = obj.getString("style");
} catch (JSONException e) {
style = null;
}
try {
min = obj.getString("min");
} catch (JSONException e) {
min = null;
}
try {
max = obj.getString("max");
} catch (JSONException e) {
max = null;
}
try {
step = obj.getString("step");
} catch (JSONException e) {
step = null;
}
try {
rows = obj.getString("rows");
} catch (JSONException e) {
rows = null;
}
// //Indexing Data..
(HERE) builder.startObject("values").field("access", access).field("role", role).field("subtype", subtype)
.field("maxlength", maxlength).field("name", name).field("description", description)
.field("className", classname).field("label", label).field("placeholder", placeholder)
.field("value", value).field("required", required).field("style", style).field("toggle", toggle)
.field("inline", inline).field("other", enableother).field("multiple", multipleFiles)
.field("content", content).field("min", min).field("max", max).field("step", step)
.field("rows", rows).endObject();
builder.endObject();
resp = client.prepareIndex("clien", userName).setSource(builder).execute().actionGet();
}
}
At (HERE) position erro keeps showing up..Cannot write a field name expecting a value.
Also is there a better way to achieve what I am trying to do here. thanks for the help.

Refresh the JTable on updating the data

Below is my code:-
public class MainScreen extends javax.swing.JFrame {
private TableRowSorter<TableModel> sorter;
public MainScreen() {
initComponents();
this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
sorter = new TableRowSorter<>(tblCustomer.getModel());
tblCustomer.setRowSorter(sorter);
List<BasicDetailsDTO> findAll = UtilDAO.getDaoBasicDetails().findAll();
System.out.println("I'm here "+findAll.size());
((DefaultTableModel) tblCustomer.getModel()).setDataVector(getDataVector(findAll), getVectorHeader());
tblCustomer.setAutoCreateRowSorter(true);
tblCustomer.getColumnModel().getColumn(0).setMinWidth(0);
tblCustomer.getColumnModel().getColumn(0).setMaxWidth(0);
}
public static Vector getDataVector(List<BasicDetailsDTO> listData) {
Vector dataVector = new Vector();
for (BasicDetailsDTO instance : listData) {
Vector row = new Vector();
row.add(instance.getId());
row.add(instance.getParticulars());
row.add(instance.getBookedBy());
row.add(instance.getContactPerson());
row.add(instance.getMobileNo());
row.add(instance.getEmail_id());
dataVector.add(row);
}
return dataVector;
}
public static Vector getVectorHeader() {
Vector header = new Vector();
header.add("ID");
header.add("Particulars");
header.add("BOOKED BY");
header.add("CONTACT PERSON");
header.add("MOBILE NO");
header.add("EMAIL ID");
return header;
}
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
displayPanel(new HomePage(), "Details Of Customer", 1200, 800);
}
private void tblCustomerKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void tblCustomerMousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tblCustomer.getSelectedRow() == -1) {
displayError("Please Select the Record");
return;
}
int option = displayConfirmDialog("Do you Really want to delete Record ?");
if (option == JOptionPane.YES_OPTION) {
String recordId = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordId));
instance.setDeleted(Boolean.TRUE);
UtilDAO.getDaoBasicDetails().remove(instance);
List<BasicDetailsDTO> findAll = UtilDAO.getDaoBasicDetails().findAll();
getDataVector(findAll);
displayMessage(" Record Deleted ");
}
}
private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (tblCustomer.getSelectedRow() == -1) {
displayError("Please select record.");
return;
}
String recordID = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordID));
displayPanel(new HomePage(instance, 1), "Customer " + instance.getBillingName(), 1200, 1000);
}
private void tblCustomerMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (evt.getClickCount() == 2) {
String recordID = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordID));
displayPanel(new HomePage(instance, 1), "Customer " + instance.getBillingName(), 1000, 1000);
}
}
private void btnViewHotelListActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
displayPanel(new ViewHotelDetails(), "List Of Hotels", 800, 700);
}
private void btnViewAgencyListActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
displayPanel(new ViewAgencyDetails(), "List Of Hotels", 800, 700);
}
private void txtSearchKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyCode() != KeyEvent.VK_ENTER && evt.getKeyCode() != KeyEvent.VK_DOWN) {
if (txtSearch.getText().trim().length() > 0) {
RowFilter<TableModel, Object> filter = new RowFilter<TableModel, Object>() {
#Override
public boolean include(javax.swing.RowFilter.Entry<? extends TableModel, ? extends Object> entry) {
String search = txtSearch.getText().trim().toLowerCase();
// System.out.println(entry.getStringValue(1));
return (entry.getValue(1).toString().toLowerCase().indexOf(search) != -1 || entry.getValue(2).toString().toLowerCase().indexOf(search) != -1 || entry.getValue(3).toString().toLowerCase().indexOf(search) != -1);
}
};
sorter.setRowFilter(filter);
//sorter.setRowFilter(null);
tblCustomer.setRowSorter(sorter);
// System.out.println("New Row is " + filter);
} else {
sorter.setRowFilter(null);
tblCustomer.setRowSorter(sorter);
}
} else {
if (tblCustomer.getRowCount() > 0) {
tblCustomer.requestFocus();
tblCustomer.setRowSelectionInterval(0, 0);
} else {
txtSearch.requestFocus();
}
}
}
private void btnInvoiceActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
InputStream in = MainScreen.class.getResourceAsStream("Passenger_Name.docx");
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
IContext context = report.createContext();
if (tblCustomer.getSelectedRow() == -1) {
displayError("Please select record.");
return;
}
String recordID = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordID));
context.put("Customer", instance);
OutputStream out = new FileOutputStream(new File("Passenger Name_Out.docx"));
report.process(context, out);
Desktop desktop = Desktop.getDesktop();
File f = new File("Passenger Name_Out.docx");
desktop.open(f);
} catch (IOException | XDocReportException ex) {
Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* #param args the command line arguments
*/
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel("com.jtattoo.plaf.texture.TextureLookAndFeel");
} catch (ClassNotFoundException ex) {
Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
}
new MainScreen().setVisible(true);
}
});
}
public static void setlblMessageDetail(String msg) {
MainScreen.lblMessage.setHorizontalAlignment(JLabel.CENTER);
MainScreen.lblMessage.setText(msg);
}
// Variables declaration - do not modify
}
Whenever I update the data within the table, the updated data is not reflected. The updated data is reflected only when I reopen the window.
Kindly help me through.
Thanks in advance.
why voids for DefaultTableModel and JTableHeader are static
remove rows from DefaultTableModel
use DocumentListener instead of KeyListener for RowFilter
why is there initialized two different LookAndFeels
updates to DefaultTableModel must be done on EDT, more in Oracle tutorial Concurrency in Swing - The Event Dispatch Thread
search for ResultSetTableModel, TableFromDatabase, BeanTableModel
rest of issue is hidden in shadowing void or classes, note remove all static declare, there should be static only main class

removing recently add JLabel on JTextPane

Hi I was doing a list of online users names using JLabel inside the JTextPane.
I used JLabel because I want the names to be clickable I was able to allign them horizontally using the styleddocument now my problem is
How can I delete the JLabel that was recently inserted ? I tried the remove method of JTextPane but it didnt work. I need to delete the JLabel when a user go offline.
My code:
public static void getUsernames()
{
try{
String query = "SELECT username FROM members WHERE status = 'offline'";
ps3 = con.prepareStatement(query);
rs2 = ps3.executeQuery();
}catch(Exception ex){ex.printStackTrace();}
}
public static void resultGetUsername(JTextPane jtp,StyledDocument sd)
{
try {
while (rs2.next())
{
final JLabel jl = new JLabel(rs2.getString("username"));
final String username = rs2.getString("username");
Border d = BorderFactory.createEmptyBorder(1,10,1,10);
Border d2 = BorderFactory.createLineBorder(Color.BLACK);
Border d3 = BorderFactory.createCompoundBorder(d2,d);
jl.setFont(new Font("Calibri",Font.BOLD,16));
jl.setBorder(d3);
jl.setOpaque(true);
jl.setBackground(Color.ORANGE);
jl.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
jl.setForeground(new Color(30,144,255));
}
public void mouseExited(MouseEvent arg0) {
jl.setForeground(Color.BLACK);
}
public void mousePressed(MouseEvent e) {
jl.setForeground(new Color(210,105,30));
jl.setBackground(new Color(154,205,50));
}
public void mouseReleased(MouseEvent e) {
jl.setBackground(Color.ORANGE);
jl.setForeground(Color.BLACK);
if(e.getClickCount() ==2)
new OneToOneChat(username);
}
});
Cursor c = new Cursor(Cursor.HAND_CURSOR);
jl.setCursor(c);
jtp.insertComponent(jl);
sd.insertString(sd.getLength(), "\n", SubPanel1.sas);
}
} catch (SQLException e) {
} catch (BadLocationException e) {
}
finally{
if (rs2 != null) {
try {
rs2.close();
} catch (SQLException sqlEx) { }
rs2 = null;
}
if (ps3 != null) {
try {
ps3.close();
} catch (SQLException sqlEx) { }
ps3 = null;
}
}
}
You can remove the labels from the JTextPane by using
setText("") or getStyledDocument().remove(0, doc.getLength())
if you need to get the labels this post could help: Get a component from a JTextPane through javax.swing.text.Element?
Then add the labels you want back into the JTextPane

Categories