Alignment of a TextField
Hello out there:
I have a Problem: when I click on a button OK a text from a Jlist must be put into a Text field.
When the text is too long for the text Field The user cannot se the beginning of the word.
That's not what I want to have. I want to have that the user cannot read the last few letters but can read the first letters
(simply making the text field longer doesn't help me)
I tried with
showingText.setHorizontalAlignment(JTextField.);But that's not the solution.
Do you know an answer?
Have you tried
showingText.setCaretPosition(0);
??
Similar Messages
-
How to set alignment in a TextField?
I need to set allignment of the text in a TextField to right. There is no such under TextField.
Anybody knows how to set alignment in a textfield in javaFX 2.0 ?
ThanksIt may be worth filing a feature request jira to get platform native support for this.
You might think that textField.setStyle("-fx-text-alignment: right;") would work, but it does not.
I guess that the -fx-text-alignment css property only right aligns multi-line text, not text within a text field.
The following code uses binding to keep Text in a TextField right aligned.
The translations place the text visually right and keyboard editing is OK.
Mouse transparency is enabled because mouse based selections still act as though the text is left aligned.
So it's not a complete solution.
public void start(final Stage stage) throws Exception {
// create a text field.
final TextField textField = new TextField("This is right aligned text");
textField.setStyle("-fx-text-alignment: right;");
textField.setMinWidth(400);
textField.setMouseTransparent(true);
// layout the scene.
final VBox layout = new VBox();
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10; -fx-alignment: center;");
layout.getChildren().addAll(textField);
Scene scene = new Scene(layout);
stage.setScene(scene);
stage.show();
// keep the text in the textbox right aligned.
final Text text = (Text) textField.lookup("Text");
rightAlign(text, textField);
textField.textProperty().addListener(new InvalidationListener() {
@Override public void invalidated(Observable observable) {
rightAlign(text, textField);
private void rightAlign(Text text, TextField textField) {
text.getParent().translateXProperty().bind(textField.widthProperty().subtract(text.xProperty().multiply(2)).subtract(text.getLayoutBounds().getWidth()));
} -
How to set alignment of the TextField
What method I shall use to set is the alignment of the TextField to have is Right Aligned?
Regds
JayI've found:
public void setComponentOrientation(ComponentOrientation o)Sets the language-sensitive orientation that is to be used to order the elements or text within this component. Language-sensitive LayoutManager and Component subclasses will use this property to determine how to lay out and draw components.
At construction time, a component's orientation is set to ComponentOrientation.UNKNOWN, indicating that it has not been specified explicitly. The UNKNOWN orientation behaves the same as ComponentOrientation.LEFT_TO_RIGHT. -
Right aligned text in textfield
Hi,
I'm trying to set the text in a textfield to be right-aligned, as it is a number textfield. I'm trying to do this with awt only (as opposed to Swing).
As our number system is Arabic, I figured on doing the following:
<code>
txtfld.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
</code>
However, that didn't do the trick, though I'm deuced if I know why!
Any other suggestions?
CheersDrClap wrote:
...Arabic numerals are the ones like 0, 1, 2, and so that are used all over the Western world...Actually, no. I always thought that, too, but I just learned that most Arabic nations use "Arabic-Indic" digits to represent numbers, not the so-called Arabic digits we use in the West (I think I'll just call those "ASCII digits" from now on). However, they are written left-to-right, not right-to-left like the rest of Arabic script. @OP, if this textfield is to contain only digits, you may want to change its internal alignment instead of its orientation. Unfortunately, I don't know how to do that with an AWT TextField. -
Vertically align top on textField
I have dynamic textField and need to align my text vertically top on textField. How can I set my text vertically top ?
I don't understand your question... do you want the text on just one line or do you want the text to go like:
a
b
c
d
Please explain a little more. -
Center Text in TextField Dynamically
How on earth do you center text within a text field
dynamically....e.g. textField.align = "center" or
textField.autoSize = "center" ....nothing works?
BTW...is it just me or is the adobe site just plain slow and
almost unusable to everyone else too. It has to be one of the
slowest loading sites I visit and the menu at top takes forever to
load completely also, Has there been discussion on that?You are using the align property incorrectly. You do not
apply it directly to the textfield but to the textformat property.
var format:TextFormat = new TextFormat();
format.align = "center";
textField.setTextFormat(format); -
Blurry text when centering textfield in datagrid
Gidday
I'm have a TextFormatAlign.CENTER alignment on the textfields in my datagrid column headers.
The text sometimes gets blurry, depending on how the window is resized.
I normally use Math.round() when positioning text fields, and I'm applying the same technique in the resize function for the header fields. The textfields themselves are rounding to the nearest x pos, but I'm guessing it's still blurry sometimes because the centered text could be 1/2 a pixel out?
Is there a way to kill the blurriness?
Cheers guysIt's a custom coded datagrid that doesn't use the normal classes. I'll get the dude that wrote it to take a look. Cheers kGlad.
-
Layout for editing database record
Hi!
I'm trying to make a JPanel display a database record for editing in a nice way, but I'm kinda stuck. Example:
Id: 10
First name: Peter
Last name: Johnson
Age: 20 and so on. The problem is that I don't know what strategy to use for the layout management, so that it looks good. I use JLabel for all labels and the Id number, since it's not editable, and JTextField s for the other data. I want the labels for the fields right aligned and the textfields left aligned "in their container", so that there is a streight line between the :s. (I hope you understand...)
Any help appreciated!
/JanThanks!
The missing link was the FlowLayout.RIGHT constant. I guess I hadn't done my homework.
Thanks for pointing that out!
/Jan -
Struts 2 Client side validation getting skipped.
I am doing a simple program using struts 2. Usually in struts2 bean class will be combined with action class unlike in struts 1.2. But for enhancing readability I made a seperate bean class and I reference it in my action class. But after seperating bean from action class Client side validation using xml is not happening. It is getting skipped. But server side validation inside execute() is happening. Will anyone please help me to find a solution to make client side validation run.
here are the different files.
1) JSP File - SEmail.jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<s:head theme="ajax" />
<title>SEmail </title>
<body>
<center><font color="blue" size="5" face="bold">
<s:label value="Secure Email - Non Registered User" /> </font></center>
<br>
<font color="red" size="3"> <s:label
value="Want to contact us?."></s:label>
</font>
<center><s:form action="/Semail.action" method="POST"
validate="true">
<s:actionerror />
<s:select label="Topic" name="user.topic" headerKey="-1" required="true"
list="#{'Plan Coverage':'Plan Coverage','Sales':'Sales','Others':'Others'}">
</s:select>
<s:textarea name="user.message" label="Message" rows="4" cols="50"
required="true" />
<br>
<s:label value="Contact Information" />
<br>
<table align="center" width="500">
<tr align="left">
<td align="left"><s:select label="Title" name="user.title"
headerKey="-1" required="true"
list="#{'-- Select One --':'-- Select One --','Mr.':'Mr.','Ms.':'Ms.','Mrs.':'Mrs.'}">
</s:select></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="First Name"
name="user.firstname" size="20" maxlength="35" required="true" /></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="Family Name"
name="user.familyname" size="20" maxlength="35" required="true" /></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="Profession"
name="user.profession" size="20" maxlength="20" /></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="Address" name="user.address"
size="20" maxlength="100" /></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="Telephone Number"
name="user.telnumber" size="20" maxlength="20" /></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="P.O. Box" name="user.pobox"
size="20" maxlength="8" /></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="City"
name="user.emirate" size="20" maxlength="35" required="true" /></td>
</tr align="left">
<tr>
<td align="left"><s:textfield label="Region and Country"
name="user.country" size="20" maxlength="35" /></td>
</tr>
<tr align="left">
<td align="left"><s:textfield label="E-mail Address"
name="user.email" size="20" maxlength="70" required="true" /></td>
</tr>
</table>
<br>
<s:file name="user.uploadFile" label="Upload Document" />
<br>
<br>
<s:submit value="Submit" align="center"></s:submit>
</s:form></center>
<font color="red" size="3"> <s:label
value="All fields marked (*) are mandatory."></s:label>
</body>
</html>
2) struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="semail" extends="struts-default">
<action name="Semail" class="semail.NonregUser">
<result name="input">/SEmail.jsp</result>
<result name="error">/SEmail.jsp</result>
<result>/SEmail.jsp</result>
</action>
</package>
</struts>
3) Bean Class - User.java
package semail;
public class User {
private String topic;
private String message;
private String title;
private String firstname;
private String familyname;
private String profession;
private String address;
private int telnumber;
private String pobox;
private String city;
private String country;
private String email;
private String uploadFile;
private String testing;
public String getTopic() {
return topic;
public void setTopic(String topic) {
this.topic = topic;
public String getMessage() {
return message;
public void setMessage(String message) {
this.message = message;
public String getTitle() {
return title;
public void setTitle(String title) {
this.title = title;
public String getFirstname() {
return firstname;
public void setFirstname(String firstname) {
this.firstname = firstname;
public String getFamilyname() {
return familyname;
public void setFamilyname(String familyname) {
this.familyname = familyname;
public String getProfession() {
return profession;
public void setProfession(String profession) {
this.profession = profession;
public String getAddress() {
return address;
public void setAddress(String address) {
this.address = address;
public int getTelnumber() {
return telnumber;
public void setTelnumber(int telnumber) {
this.telnumber = telnumber;
public String getPobox() {
return pobox;
public void setPobox(String pobox) {
this.pobox = pobox;
public String getCity() {
return city;
public void setCity(String city) {
this.city= city;
public String getCountry() {
return country;
public void setCountry(String country) {
this.country = country;
public String getEmail() {
return email;
public void setEmail(String email) {
this.email = email;
public String getUploadFile() {
return uploadFile;
public void setUploadFile(String uploadFile) {
this.uploadFile = uploadFile;
public String getTesting() {
return testing;
public void setTesting(String testing) {
this.testing = testing;
This is my bean class. Instead of putting it with action class NonregUser.java , I have seperated it out for readability. And I am referencing it in the action class.
4) Action Class - NonregUser.java
package semail;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import com.opensymphony.xwork2.ActionSupport;
public class NonregUser extends ActionSupport implements ServletRequestAware,
ServletResponseAware {
private static final long serialVersionUID = 2451855813074437309L;
HttpServletRequest request = null;
HttpServletResponse response = null;
private User user = null;
/* I am referencing my bean class here instead of writing all the getters and setters here.*/
public User getUser() {
return user;
public void setUser(User user) {
this.user = user;
public String execute() throws Exception {
System.out.println("Validating login");
if(user!=null){
System.out.println(user.getFirstname());
System.out.println(user.getEmail());
System.out.println(user.getTopic());
System.out.println(user.getTitle());
// this server side validation is happening
if (user.getTitle().trim().equals("-- Select One --")) {
addActionError("Please select Title");
return ERROR;
} else {
return SUCCESS;
}else{
return SUCCESS;
public void setServletRequest(HttpServletRequest arg0) {
System.out
.println("HttpServletRequest : " + NonregUser.this.getClass());
request = arg0;
public void setServletResponse(HttpServletResponse arg0) {
System.out.println("HttpServletResponse : "
+ NonregUser.this.getClass());
response = arg0;
This is my acation class. Here I am referencing my bean class User.java.
5) xml validation file - NonregUser-validation.xml
/*This client validatin is not working*/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="topic">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please select the Topic</message>
</field-validator>
</field>
<field name="message">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please enter Message</message>
</field-validator>
<field-validator type="stringlength">
<param name="maxLength">8000</param>
<message>Message cannot contain more than 8000 characters</message>
</field-validator>
</field>
<field name="title">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please select the Title</message>
</field-validator>
</field>
<field name="firstname">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please enter First name</message>
</field-validator>
<field-validator type="stringlength">
<param name="maxLength">35</param>
<message>First Name cannot contain more than 35 characters</message>
</field-validator>
</field>
<field name="familyname">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please enter Family name</message>
</field-validator>
<field-validator type="stringlength">
<param name="maxLength">35</param>
<message>Family Name cannot contain more than 35 characters</message>
</field-validator>
</field>
<field name="emirate">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please enter Emirate/City</message>
</field-validator>
</field>
<field name="email">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please enter Email address</message>
</field-validator>
<field-validator type="email">
<message>Please enter a valid Email address</message>
</field-validator>
</field>
</validators>
6) web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/SEmail.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/pagenotfound.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
</web-app>
Edited by: L-J-K on Jul 22, 2008 5:22 AMI was trying to do it through creating a new validators.xml where I would redefine all struts built in validations and add de definition for my custom Validation (<validator name="checkUser" class="com.custom.CustomUserValidator"/>). Then I define the ActionClassName-action-validation.xml refering to my custom validator (checkUser). The com.custom.CustomUserValidator Class has to extend FieldValidatorSupport or ValidatorSupoort (depending on what kind of validation).
Ok that's it, this is the theory, now the custom validator (checkUser) is executed before my action but I don't know how to do it so that if the validation fails i return to the same page showing the error message to the user without having to execute the target action. Does anyone know how to do this???? -
Gridbaglayout over more than one panel
hi
i have a problem aligning my label / textfield combos.
there are several rows where each contains a label and a textfield. my problem is that they are distributed over more than one panel.
i have one gridbaglayout which manages my labels / textfields. what i want is that the labels are ALL the same width - it works fine for each panel but i cant bring that stuff to work that the widest label stands for ALL other labels.
i hope you can imagine what my problem is. please help since i am kinda unsuspecting ;)
thxHey,
Please download the application mentioned in it.
When i have excuted the application i could find sort enabled for all the columns.
wdContext.currentContextElement().getTableSorter().sort( wdEvent, wdContext.nodeTableSet() );
Please check it..
Jithin
Edited by: jithin james on Apr 16, 2009 10:47 AM -
Hi all,
I am displaying some numbers in a JCombobox. To center-align the numbers, I used a custom ListCellRenderer(extending JLabel) where I added the code setHorizontalAlignment(JLabel.CENTER);
But the number displayed in the combobox is left aligned. Only other numbers inside the combobox are center-aligned. Pls help me out.You'll always have to set the alignment of the textfield used by the editor component of the combo box, you can try something like this:
ComboBoxEditor editor=(ComboBoxEditor)myComboBox.getEditor();
JTextField TF=(JTextField)editor.getEditorComponent();
TF.setHorizontalAlignment(JLabel.CENTER);;o)
V.V. -
I wonder what title would get someone to look at my post.
I want to change the alignment of a TextField to RIGHT_ALIGNMENT. I cannot figure out how to do it. I've looked through the API documentation. I don't want to use Swing. Could someone please help. Thanks.
The Doctor comes through! Like you said, "You can't do that," is not exactly what I wanted to hear, but it was definetely more than any other reply. You gave me a diagnosis.
I had thought about writing my own subclass of TextField with right alignment, but I don't think I'm advanced enough to do that, yet.
Maybe I can use a label and make it look like a text field. I think that's probably going to be the easiest thing for me to do right now. Although, I am still interested in finding out a way to change the alignment of a text field.
macrules2:
JTextField is definetely an option, but at my present level of expertise, I'm trying not to get too involved with Swing (at least not Swing & applets). I have some unsolved problems with applets using Swing...namely: they won't work in a web browser. I've asked for help here at these forums, but nothing helped. The problem may be that I just didn't understand the solutions that I was given, but whatever the case may be, I couldn't get my applets that use Swing to display in a web browser.
Everyone:
I think I'll try a different subject next time. -
How to achieve this through vector
I am having a Vector which is having Data like[a,b,c,d,ef,g,aa,bb]. I want to display it like
a b c d
ef g aa bb
I am doing this way
int size=v.size();
String s[]=new String[size];
v.toArray(s)
<%for(int i=0;i<size;i=i+4){
<td width="5%"><input type="checkbox" name="chk" value="<%=s%>"></td>
<td width="5%" align="left" class='textfield' class='labelTohma'><%=s[i+1]%></td>
<td width="25%" align="left" class='textfield' class='labelTohma'><%=s[i+3]%></td>
%>If I understand correctly, you want the elements of vector v to be displayed in rows with columnCount columns:
<table>
<tbody>
<%
Enumeration e = v.elements();
int rowCount = (int)Math.ceil(v.size() / columnCount);
for(int row = 0; row < rowCount; row++) {
%>
<tr>
<%
for(int col = 0; col < columnCount; col++) {
if(e.hasMoreElements()) {
%>
<td><%= e.nextElement() %></td>
<%
%>
</tr>
<%
%>
</tbody>
</table> -
Need Help with Listener on JInternalFrame
Below is the code as it is currently.
public class addCustomer extends JInternalFrame implements ActionListener{
//Variable declarations here
private JPanel panel = new JPanel();
private JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,icon1;
private JTextField CustNum,CFName,CSName,Address1,Address2,City,PostCode,Tel,Cell;
private JButton Cancel, Add;
private ImageIcon pic,FrmPic;
addCustomer() {
super ("Add New Customer",true,true,true,true);
setSize(350,370);
setResizable(false);
On the Frame I have a textfield that I would like to add a listener to. When text is typed into the textfield it should enable a JButton on the frame. My problem is that as soon as I implement KeyListener or EventListener on the above code I get an error of the class is not defined as abstract. If I define it as abstract my main declaration that looks like this gives me an error :
public static void main(String args[]){
new Video().show();
Can anyone help me with a work around.
AlexanderStill have an error in the code. I don't know what I am doing wrong. this is the code so far.
//This class will create the the Panel for Adding new Customers
package VideoShop;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.io.*;
import javax.swing.event.*;
public class addCustomer extends JInternalFrame implements ActionListener{
//Variable declarations here
private JPanel panel = new JPanel();
private JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,icon1;
private JTextField CustNum,CFName,CSName,Address1,Address2,City,PostCode,Tel,Cell;
private JButton Cancel, Add;
private ImageIcon pic,FrmPic;
addCustomer() {
super ("Add New Customer",true,true,true,true);
setSize(350,370);
setResizable(false);
//Sets the layout for the panel
panel.setLayout(null);
//Creates the labels
label1 = new JLabel("Customer Nr");
label2 = new JLabel("First Name");
label3 = new JLabel("Surname");
label4 = new JLabel("Address");
label5 = new JLabel("Address");
label6 = new JLabel("City");
label7 = new JLabel("Postcode");
label8 = new JLabel("Tel Nr");
label9 = new JLabel("Cell Nr");
//Creates the Textfields
CustNum = new JTextField();
CustNum.setEditable(false);
CFName = new JTextField();
CSName = new JTextField();
Address1 = new JTextField();
Address2 = new JTextField();
City = new JTextField();
PostCode = new JTextField();
Tel = new JTextField();
Cell = new JTextField();
//Creates the buttons
Cancel = new JButton("Cancel");
Add = new JButton("Add");
//Sets the alignment of the label controls
label1.setBounds(20, 20, 90, 20);
label2.setBounds(20, 50, 90, 20);
label3.setBounds(20, 80, 90, 20);
label4.setBounds(20, 110, 90, 20);
label5.setBounds(20, 140, 90, 20);
label6.setBounds(20, 170, 90, 20);
label7.setBounds(20, 200, 90, 20);
label8.setBounds(20, 230, 90, 20);
label9.setBounds(20,260,90,20);
//Sets the alignment of the Textfield controls
CustNum.setBounds(100,20,90,20);
CFName.setBounds(100, 50, 90, 20);
CSName.setBounds(100, 80, 90, 20);
Address1.setBounds(100, 110, 130, 20);
Address2.setBounds(100, 140, 130, 20);
City.setBounds(100, 170, 100, 20);
PostCode.setBounds(100, 200, 65, 20);
Tel.setBounds(100,230, 90,20);
Cell.setBounds(100, 260, 90, 20);
//Sets the alignment of the Button controls
Add.setBounds(200, 310, 90, 20);
Cancel.setBounds(85,310,90,20);
//Creates an icon on the panel
pic = new ImageIcon("/VideoShop/NotePad.gif");
icon1 = new JLabel(pic);
icon1.setBounds(280,10,50,50);
//Adds Mnemonics
Cancel.setMnemonic('c');
Add.setMnemonic('a');
//Adds listener to the Cell TextField to help with validation
Cell.getDocument().addDocumentListener(new DocumentListener(){
public void changeUpdate(DocumentEvent e){
public void removeUpdate (DocumentEvent e){
adjust(e);
public void insertUpdate(DocumentEvent e){ //ERROR////////////
adjust(e);
//Adds listeners to the buttons on the panel
Cancel.addActionListener(this);
Add.addActionListener(this);
//Adds the controls to the panel
panel.add(label1);
panel.add(label2);
panel.add(label3);
panel.add(label4);
panel.add(label5);
panel.add(label6);
panel.add(label7);
panel.add(label8);
panel.add(label9);
panel.add(CustNum);
panel.add(CFName);
panel.add(CSName);
panel.add(Address1);
panel.add(Address2);
panel.add(City);
panel.add(PostCode);
panel.add(Tel);
panel.add(Cell);
panel.add(Cancel);
panel.add(Add);
panel.add(icon1);
//Gets the next customer number from the database
//Variables for the database
String dbuser = "";
String dbpasswd = "";
String DriverPrefix = "jdbc:odbc:";
String DataSource = "Video";
//Holds the value from the database
String val1;
//SQL String for writing data to database
String SQLstring = "SELECT CustNum FROM Customers";
//Loads the driver for the database
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Error Loading driver\n"+e,"Driver Load Error",JOptionPane.WARNING_MESSAGE);
Statement stmt = null;
Connection con = null;
//Create a connection to the database.
try {
con = DriverManager.getConnection(DriverPrefix+DataSource,dbuser, dbpasswd);
stmt = con.createStatement();
}catch (Exception e) {
JOptionPane.showMessageDialog(null,"Cannot connect to Database\n"+e,"Connection Error",JOptionPane.WARNING_MESSAGE);
ResultSet rs = null;
//Gets data from the database
try {
rs = stmt.executeQuery(SQLstring);
while (rs.next()){
val1 = rs.getString(1);
int val2 = Integer.parseInt(val1);
val2++;
CustNum.setText(String.valueOf(val2));
} catch (Exception e){
JOptionPane.showMessageDialog(null,"Cannot connect to database\n"+e,"Communication Error",JOptionPane.WARNING_MESSAGE);
try {
con.close();
} catch (Exception e){
JOptionPane.showMessageDialog(null,"Cannot close database\n"+e,"Error",JOptionPane.WARNING_MESSAGE);
//Adds the panel to the InternalFrame and display it
getContentPane().add(panel);
show();
//Here all action events are processed
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Cancel){
dispose();
if (e.getSource() == Add){
ToDatabase();
//Here the document event is processed
public void adjust(DocumentEvent e){
Cell.setEnabled(e.getDocument().getLength()>0);
//Here the data will be sent to the database
public void ToDatabase() {
//Variables for the database
String dbuser = "";
String dbpasswd = "";
String DriverPrefix = "jdbc:odbc:";
String DataSource = "Video";
//SQL String for writing data to database
String SQLstring ="INSERT INTO Customers VALUES('"+CustNum.getText()+"', '"+CFName.getText()+"','"+CSName.getText()+"','"+Address1.getText()+"','"+Address2.getText()+"','"+City.getText()+"','"+PostCode.getText()+"','"+Tel.getText()+"','"+Cell.getText()+"')";
//Loads the driver for the database
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Error Loading driver\n"+e,"Driver Load Error",JOptionPane.WARNING_MESSAGE);
Statement stmt = null;
Connection con = null;
//Create a connection to the database.
try {
con = DriverManager.getConnection(DriverPrefix+DataSource,dbuser, dbpasswd);
stmt = con.createStatement();
}catch (Exception e) {
JOptionPane.showMessageDialog(null,"Cannot connect to Database\n"+e,"Connection Error",JOptionPane.WARNING_MESSAGE);
//Transfer data to database
try {
stmt.executeUpdate(SQLstring);
con.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Cannot update database\n"+e,"Communication Error",JOptionPane.WARNING_MESSAGE);
dispose();
The error that I receive is this:
VideoShop/addCustomer.java [98:1] <anonymous VideoShop.addCustomer$1> is not abstract and does not override abstract method changedUpdate(javax.swing.event.DocumentEvent) in javax.swing.event.DocumentListener
public void insertUpdate(DocumentEvent e){ //ERROR////////////
^
1 error
Errors compiling addCustomer.
Is there a way around this or should I rewrite the whole class.
Thanks
Alexander -
After reading this: http://java.sun.com/docs/books/tutorial/2d/text/drawmulstring.html , I'm left wondering why there is no method in Graphics2D that encapsulates this functionality.
14 lines of code vs 1.Well, I meant by standard that when you create a textfield it
is automatically a dynamic textfield, and when I create a textfield
it is automatically a static testfield.
I made a small picture story to explain my findings:
First I have a static textfield and a dynamic one, you can
see that the dynamic one has a border, the static one has not:
http://hltown.de/userftp/hl_protector/temp/bild1.png
When I create the two buttons they look alike and there seems
to be no difference:
http://hltown.de/userftp/hl_protector/temp/bild2.png
Both buttons have the same dimensions, in that case width =
104.0 and height = 71.1. I use the code we all know to create two
instances, one for the first button, one for the second:
http://hltown.de/userftp/hl_protector/temp/bild3.png
As you can see the dynamic textfield button is correctly
scaled and aligned, the static textfield button is not.
I go into the second button and "break apart" the static
textfield two times, so it becomes a solid vector graphic:
http://hltown.de/userftp/hl_protector/temp/bild4.png
Now the second button is smaller and looks like this:
http://hltown.de/userftp/hl_protector/temp/bild5.png
The new buttons dimensions are now width = 52.5 and height =
43.5. When I change the width and height for the second button in
the AS code to these new values, the result looks like this:
http://hltown.de/userftp/hl_protector/temp/bild6.png
Maybe you are looking for
-
I may have inadbertenly deleted CS5 Photoshop in error or it never installed. I had a time when HD was 99 percent full so I started deleting CS3,4 etc Photoshop, Bridege. I remember downloading for this laptop the CS5 for Mac , Bridge, Raw, DNg all t
-
I no longer have any contractual obligations, and i have iphone 3GS and iphone 4, I want to change carrier, but my phones are locked. Help I live in Lithuania. BR
-
I am unable to activate an old windows copy of CS3 that I have. Did previously install it on other computers which I then failed to deactivate before discarding them. What can I do now?ACT
-
How can I do to mount within Solaris a FAT partition contained in the same drive?
-
hi after creating the sales order we are getting sales document conformation(three pages) thruogh out put determination, but we need first page only fro conformation, how can we configure? Thank u