This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Jennifer Garrett

Greenhorn
+ Follow
since Oct 31, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jennifer Garrett

change this line
fireTableRowsDeleted(Row, 0);
to:
fireTableRowsDeleted(Row, Row);
I think the fireTableRowsDeleted method expects the first argument to be the first row to delete, and the second argument is the last row to delete, and it deletes all the rows between the first argument and the second argument.
16 years ago
hmm, what do you do in the class that instantiates your subclass of AbstractTableModel? Do you have a listener to wait for some action indicating you want to delete a row and then call the method (either removeRow or deleteRow, whichever you use in the class that extends AbstractTableModel).
tModel.removeRow(tableIndex);
tModel is the instance of the class that extends AbstractTableModel, and tableIndex is the row number to delete.
16 years ago
What if you change the deleteRow method to this:
public void removeRow(int rowNumber) {
data.removeElementAt(rowNumber);
fireTableRowsDeleted(rowNumber, rowNumber);
}
The data variable is a vector of vectors containing all the data in the table cells.
16 years ago
StringBuffer newText = new StringBuffer("");
ResultSet rs5 = stmt5.executeQuery(SQLstmt5);
while (rs5.next()){
String operName = rs5.getString("name");
String operName_NoSpc = operName.trim();
newText.append(operName_NoSpc);
newText.append("<br>");

// HtmlPane.setText(operName_NoSpc); //one item at a time
allPages[z] = operName_NoSpc;
z++;
}
HtmlPane.setText(newText.toString());
rs5.close();
16 years ago
You could do something like this, since you already have a while loop. You don't need the array allPages, but if you really want to use it you can. You could loop through all the elements in the array and append them to the stringbuffer, but it might be easier to do it this way:

StringBuffer newText = new StringBuffer("");
ResultSet rs5 = stmt5.executeQuery(SQLstmt5);
while (rs5.next()){
String operName = rs5.getString("name");
String operName_NoSpc = operName.trim();
newText.append(operName_NoSpc);
// HtmlPane.setText(operName_NoSpc); //one item at a time
allPages[z] = operName_NoSpc;
z++;
}
HtmlPane.setText(newText.toString());
rs5.close();
16 years ago
oops, I forgot how to write > and < in html. I was trying to say insert some <p> and <br> to the text before doing setText().
16 years ago
if you use HTML (setContentType("text/html") then you just insert some
or
between the lines and you only call setText once with all the lines and the
or
line separators.
16 years ago
call
setContentType("text/html")
for the JEditorPane
and add html tags to the text to change the font.
17 years ago
Try this line after you define dialog as the JDialog:
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE );
17 years ago
Maybe you should try adding an Item Listener and whenever something is selected or deselected you can do whatever. There's an example in the java tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#checkbox
17 years ago
I think you need to use DefaultTableModel for adding and removing rows. Your code might be something like this:
String[] mycolumns = {"column 1 title", "column 2 title"};
String[][] mydata = {{"foo", "bar"}, {"aaa", "bbb"}};
DefaultTableModel mytableModel = new DefaultTableModel(mydata, mycolumns);
JTable mytable = new JTable(mytableModel);
JScrollPane myscrollpane = new JScrollPane(mytable);
// ... somehwere later, whenever you want to remove a row...
int rowNumber = 0;
mytableModel.removeRow(rowNumber); // remove the first row
17 years ago
You need to insert html tags in the text that goes in the JEditorPane. In my code, I wait for the user to click the ok button and then I make some words red if there is a problem with those words. If the data is changing often, you probably want to use setText() to change the text in the JEditorPane, otherwise you can create a file and use setPage() to tell the JEditorPane where to find the text.
This is part of the code from something similar that I did recently.

final JEditorPane myEditorPane = new JEditorPane();
myEditorPane.setContentType("text/html");
final HTMLEditorKit editor =
(HTMLEditorKit)myEditorPane.getEditorKit();
myEditorPane.setPreferredSize(new Dimension(100, 100));
JScrollPane myScrollPane = new JScrollPane(myEditorPane);
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do whatever you want when the button is pushed
String newData = myEditorPane.getText();
StringBuffer myDataBuffer = new StringBuffer(newData);
// change the data, insert html tags
myEditorPane.setText(myDataBuffer.toString());
}
});
myPanel.add(myScrollPane);
myPanel.add(okButton);
17 years ago
I am trying to make a JEditorPane that the user can type anything in it, when they click a button, I parse the input and color some of the text red if the user mistyped something, so I insert html tags that set font color="red". The problem is when I call the setText method to update the data in the JEditorPane, I see the word "head" twice at the top with a box around each "head", then below that I see the html text that I expected. Has anyone else had this problem with the "head" at the top? Any ideas about how to get rid of the "head" part? Thanks!
Jennifer
17 years ago