JTextPane + Getting a row count..

Hi,
I've been looking for a solution to this, but can't find one already in the forum. there are some close .. but this is my problem..
I'm looking to get the current row count of a JTextPane... I'm not looking to get the count of '\n'.... I want to take the wrapping into account .. so if I resize the JTextPane, the row counts will change accordingly.
The reason I'm looking for this information is so I can set the size on the JTextPane so that it always shows the data.. but when it only has one line, I only want it to take up space for one line (the reason for this is I don't want vertical scrollbars appearing where they're not needed)
I hope I have given enough information for someone to help me out..
Thanks :)
/Balmark

Unfortunately WrappedPlainView's methods and inner classes are private so we can't access it normal way.
This is an example of hack access to WrappedPlainView. In some cases it can throw access violation exception.
best regards
Stas
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;
import java.lang.reflect.*;
public class Test {
JScrollPane scroll;
JTextArea textArea=new JTextArea();
public Test() throws Exception {
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textArea.setLineWrap(true);
textArea.setText("12345 67890 12345 67890 12345 67890\n 12345 67890 12345 67890 12345 67890");
scroll=new JScrollPane(textArea);
frame.getContentPane().add(scroll);
JButton b=new JButton("print line count");
frame.getContentPane().add(b,BorderLayout.SOUTH);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.err.println(textArea.getUI().getRootView(textArea).getView(0).getViewCount());
WrappedPlainView pv=(WrappedPlainView)textArea.getUI().getRootView(textArea).getView(0);
int lineCount=0;
for(int i=0; i<pv.getViewCount(); i++) {
View pvLine=pv.getView(i);
try {
Class cl=pvLine.getClass();
Field f=cl.getDeclaredField("nlines");
f.setAccessible(true);
lineCount+=f.getInt(pvLine);
/* Method methodLineCount=cl.getDeclaredMethod("calculateLineCount",null);
methodLineCount.setAccessible(true);
Object result=methodLineCount.invoke(pvLine,null);
System.err.println("Line count="+result.toString());*/
catch (Exception ex) {
ex.printStackTrace();
System.err.println("Line count="+lineCount);
frame.setSize(200,200);
frame.setLocationRelativeTo(null);
frame.show();
public static void main(String[] args) throws Exception {
new Test();
}

Similar Messages

  • How to get the row Count of a ResultSet

    How to get the row Count of a ResultSet

    Hi
    I'v tried rennie1's way ,but I only get zero,my code is:
    rs.executeQuery("select count(*) from t_test");
    if (rs.next()) int rowCount=rs.getInt(1);
    I also tried barni's way ,but the method rs.last() and rs.beforeFirst() throw a same Exception
    I tried another way,the code is:
    while rs.next(){
    // Do nothing ,just move the cursour to the last row
    int rowCount=rs.getRow()
    However,the rowCount still equal zero
    Any help would be greatly apprecite!
    note:
    I get connection by DataSource's JNDI name from client, the Server is Weblogic Server 6, the DBMS is Oracle.

  • How to get  visible row  count  in JTable ?

    I have one table which is added to one scroll pane. For example my table have total 1000 rows, but at a time only 20 rows should be visible to the scroll pane. And I want to scroll the rows and show only 20 at a time.When user scrolls JTable then next time he can view only 1 to 21, then 2 to 22, and so on. I want to know how to get that number which represents the visible row( in this case it is 20).So kindly help me how to get visible row count. Any help regarding this will be appriciated.
    Thanks and Regards,
    Sheetal

    how to get visible row count.First you need to get the viewport used by the scrollpane. Then you can use methods like getViewPosition() and getViewSize() to get information about the current postition of and size of the viewport.
    Then you can use the table method getRowAtPoint(). to determine the first and last visible row which can then be used to calculate the visible row count.
    When user scrolls JTable then next time he can view only 1 to 21, then 2 to 22, and so onThis is the default behaviour when a "block" scroll is done.
    However when you click on the arrow button on the scrollbar it will only scroll a single row. You could override the getScrollableUnitIncrement() method to return the value from the getScrollableBlockIncrement() method.
    However the user can still drag the scrollbar manually which would cause a problem. So you would also need to remove the MouseMotionListeners from the scrollbar to prevent this.

  • Problem w/: Error while getting estimated row count for view

    JDev 10.1.3 - Steps
    1. created a ADF VO w/ one bind variable vNAME.
    2. Created a basic jspx page, use the data control pal. to drop in VO w/ executeparam option. Use the data control pal to drop in VO w/ ADF Read-Only Table w/ select and sort option. Selected all VO columns in table.
    3. Following Error msg occurs when running jspx page -
    oracle.jbo.DMLException: Error while getting estimated row count for view object CategoryView, statement SELECT count(1) FROM (SELECT
    CATEGORY.CATID CATID,
    CATEGORY.NAME NAME,
    CATEGORY.PICTURE PICTURE,
    CATEGORY.ACTIVE ACTIVE
    FROM
    CATEGORY
    WHERE
    (CATEGORY.NAME LIKE UPPER(:vName)||'%')) .
    Tested SQL Statement in SQL Worksheet works ok (with a Value replacing ':vName').
    Can anyone advise - seems to be a straight forward process that is returning this error msg. I have tried variations of the SQL stmt with no luck. The jspx page errors when the ADF Read-Only Table is added.

    I seem 2 have the same error, in a slightly different situation.
    I have a view which subclasses a Entity with a history column 'CreatedOn'. When performing a quick search/filter on this column I get the same error. The ADF app is build on a DB2 database, so no named parameters here. Instead invalid SQL is created when executing the estimated row count. The WHERE clause contains 'CreatedOn = null', should be 'CreatedOn is null'. Furthermore the input of my quick search is not filled in this clause.
    Any help would be appreciated

  • Unable to get the row count of supplier site for each supplier

    Hi,
    In the sourcing module, suppliers page is having an advanced table in which there is a field 'supplier' and another filed 'supplier sites' (supplier field is of type picklist).Now, how can i get the count of 'supplier sites' for each supplier???

    Hi sumit,
    Thanks for the reply, can u please help in writing the code to loop through the VO...
    I was trying to get the first row and then finding the count of supplier sites, but in each iteration of for loop(for each row) i am getting the same count value for each and every row...
    Code :
    int j=vo.getrowcount();//count of no. of rows
    for (int i=0;i<j;i++)
    row=(xxVORowImpl)rowsetiterator.getRowAtRangeIndex(1);
    int a=am.getSupplierSitesVO.getRowCount();//this is the view object in the pick list
    oapagecontext.writeDiagnostics(this,"value of   a is :"+a,1);
    this code is giving row count of last row of supplier.
    How to get the count for each and every row of supplier sites ?
    Thanks.

  • ViewObject getting as row count zero ( JDeveloper 10.1.3)

    Hi All,
    In my code when i tried to get the viewobject rows, which had a viewlink created inside the code using the createLink() method, the viewobject is coming as with zero row count.
    I tried , vo.setRangeSize(-1) , vo.executeQuery() as well but still its not updated.
    But the same code is working in 9.0.4 not in 10.1.3

    Hi Frank,
    I am not sure whether its an upgrade bug or not...., is there any way to trace the this?.

  • Get Table Row Count

    hi folks,
    How to get a tables' row count (number of records)?
    Values of table are filled by an RFC return structure. Or how can we get the number of records in the RFC return structure?
    thanks in advance
    nikhil

    Hi,
    Check the size of the node bound to the table
    lets say orders is the node bound to the table
    //Replace orders with the node bound to your table.
    wdContext.nodeOrders().size();
    Regards
    Ayyapparaj

  • How to get the row count of a Table DATA?

    Hi,
      In my Adobe form layout, I have a Table node which is bound to an internal table. Now at runtime, I want to determine the number of rows that the internal table has, i.e the row count of the DATA node of the Table. How will I be able to determine the no. of rows of the internal table at runtime using Javascript? I am not being able to find any suitable answer in this forum. Please suggest. Thanks in advance.

    Hi,
    If you bind the interactive form table to the internal table and specify some properties, the table will vary its row size according to the number of data available in the internal table.
    You have to wrap the table in a sub form,  check 'allow page break with contents' and property 'flowed'.
    the table will automatically increase its row size...
    Is this the reason for which you wanted for the row count..?
    If so, this will help you..
    Regards.
    Surya

  • The best way to do paging and get total rows count given a sql statement

    Hi,
    Just got a quick question.... what is the best way to do paging as well as the total rows count given by a sql statement.
    e.g. "select * from emp"
    1. I need to know the total row count for this statement.
    2. I also need to do a 10 rows per page....
    Is there a way to do it in a SINGLE statement for best performance?
    Thanks experts.

    Sounds more like a "formatting" problem...
    If Sql*plus is your reporting tool, check out the guide:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/toc.htm

  • Need to get a row count

    How do I rewrite the following NOT to retrieve the actual rows, but to retrieve the COUNT only (because the number of rows is very large - takes tons of resources to retrieve).
    Thanks for any help,
    Russ
    ExpressionBuilder eb = new ExpressionBuilder();
    ReportQuery qry = new ReportQuery(eb);
    qry.setReferenceClass(Employee.class);
    qry.setSelectionCriteria(eb.get("lastNameUpper").like(lName));
    Vector v = (Vector)session.executeQuery(qry);
    return v.size();

    ExpressionBuilder eb = new ExpressionBuilder();
    ReportQuery qry = new ReportQuery(eb);
    qry.setReferenceClass(Employee.class);
    qry.addCount();
    qry.setSelectionCriteria(eb.get("lastNameUpper").like(lName));
    Vector v = (Vector)session.executeQuery(qry);
    return (Number) ((Map) v.get(0)).get("COUNT");

  • How to get Valid Row Count on Matrix

    Our code reads certain fields on the marketing document form (both Header and Line fields) every time before Add or Update the document.
    To read the lines, we have a function "GetLinebyUI(i, FormType, other parameters...)" that is called for every Line on the Matrix. It looks like:
    For i=1 to MaxRow
    '...Call GetLinebyUI(i, FormType, ...) function...
    next i
    We initially had MaxRow = oMatrix.RowCount
    And we found:
    1. It works correctly when updating Closed QU, Closed OR, DN,RE,IN and CN. For example, when updating Comment on a single line Sales Quotation, it reads oMatrix.RowCount=1
    2. When Updating Open Sales Quotation or Open Sales Order, RowCount reads one more line than what is on the Form. So MaxRow should be oMatrix.RowCount-1. For example, updating Comment on an Open Sales Order with only one line, oMatrix.RowCount reads '2', and we need MaxRow to be '1'. Otherwise it will give Exception error for every field it tries to read on the second line.
    3. When Adding documents (all A/R documents), RowCount reads one more line than what is entered on the Form, so MaxRow needs to be oMatrix.RowCount-1.
    How can we correctly get MaxRow according to the FormType and if it's to be added or updated?

    Hi Satish,
    Thanks for your reply.
    I should have mentioned that there are chances to update DN,RE,IN and CN - either Open or Closed (e.g. update a header level User-Defined field, or update the Comment). In these cases, it should be RownCount for both Open and Closed. So it looks like we need more than just doc status to seperate the situations.
    Here is a comparison of situations (RC stands for RowCount):
    Action- Status- QU/OR--- DN/RE/IN/CN/PD/PU/PC
    Add------ Open--- RC-1-- RC-1
    Update- Open- RC-1-- RC
    Update- Closed- RC------ RC
    Thanks again for the input.
    Yi
    Message was edited by:
            Yi Liao

  • Get row count for different tables to the same line

    How can I get the row count for different tables in one line:
    SELECT count(A), count(B), count(C) from table tb_a A , tb_b B, tb_c C;
    Thanks!

    >
    Hi,
    How can I get the row count for different tables in one line:
    SELECT count(A), count(B), count(C) from table tb_a A , tb_b B, tb_c C;Something like this? One of the many uses for CTE's - Common Table Expressions - AKA
    subquery refactoring. Worth getting to know - very handy!
    with acount as
      select count(*) as counta from dual  -- put your table name here
    bcount as
      select count(*) as countb from dual  -- put your table name here
    ccount as
      select count(*) as countc from dual  -- put your table name here
    select a.counta, b.countb, c.countc from acount a, bcount b, ccount c;HTH,
    Paul...
    Edited by: Paulie on 25-Jul-2012 17:44

  • Report.Services 2008 - get page-count or row-count in the c#-code

    hello
    is it possible to get from the ReportViewer-control / ServerReport the page-count or row-count after the
    reportViewerCheck.ServerReport.Refresh();
    statement ??
    many thanks in advance for any clue & regards
    Michael

    Hi Michael,
    Yes, you can get them. For row count, you can add a parameter to store the row count of your dataset in your report.
    Here are the steps:
    1.     Add 2 datasets in your report, one for report use and the other on is to row count use. For instance:
    DataSet1: SELECT     HumanResources.vEmployee.* FROM         HumanResources.vEmployee
    DataSet2: SELECT     COUNT(*) FROM         HumanResources.vEmployee
    2.     Add a parameter, set the parameter’s default value set to Get Values from a query and select DataSet2.
    Then, in your ASP.NET web application code you can use the following function to get the row count of the report:
    private int GetReportRowCount(ReportViewer report)
                return Convert.ToInt32(report.ServerReport.GetParameters()[0].Values[0].ToString());
    For page count, you can refer to the following code:
    private int GetReportPageCount(ReportViewer report)
                return report.ServerReport.GetTotalPages();
    You may not get the correct row count and page count in after executing Refresh () method, that’s because when you run this method, it will start another thread to refresh the report and the code below Refresh () method will not wait refreshing complete but run it. For instance, you may get the page count as o if you run the following code in the Button event:
    // Click this Button to refresh the ReportViewer1
            protected void btnGetPageCount_Click(object sender, EventArgs e)
                // Refresh the ReportViewer1
                this.ReportViewer1.ServerReport.Refresh();
                // Get ReportViewer1's page count and display in the txtPageCount TextBox
                this.txtPageCount.Text = this.ReportViewer1.ServerReport.GetTotalPages().ToString();
    You can run the refresh in separate events and get page count in another event, such as below code:
            // Click this Button to refresh the ReportViewer1
            protected void btnGetPageCount_Click(object sender, EventArgs e)
                // Refresh the ReportViewer1
                this.ReportViewer1.ServerReport.Refresh();
            // Display the txtPageCount's text to ReportViewer's page count
            protected void btnGetPageCount2_Click(object sender, EventArgs e)
                // Get ReportViewer1's page count and display in the txtPageCount TextBox
                this.txtPageCount.Text = this.ReportViewer1.ServerReport.GetTotalPages().ToString();
    Hope this helps! I would suggest you post a new thread in Visual Studio Report Controls forum if you need more help about using ReportViewer in ASP.NET web application.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Getting row count of file into table column

    Hi experts,
    I want to insert the row count of the file into a table column for generating a summary file containing the detials of all the files generated for the day along with the row count and also for audit purpose.
    My design is to create table in the summary file format & update the data's in it then using OdiSqlUnload to generate the required summary file, for this purpose I need to insert the row count of the file generated.
    I tried to get the row count using the http://odiexperts.com/get-file-length-and-header-in-operator post. But passing the "lines" value into a ODI variable or inserting into a table column is not working.
    Please help or suggest what can be done to achive the above scenario.
    Thanks in advance.

    There are a few excellent examples at :- COUNT
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Most efficient way to get row count with a where clause

    Have not found a definitive answer on how to do this.  Is there a better way to get a row count from a large table that needs to satisfy a where clause like so:
    SELECT COUNT(*) FROM BigTable WHERE TypeName = 'ABC'
    I have seen several posts suggesting something like 
    SELECT COUNT(*) FROM BigTable(NOLOCK);
    and 
    selectOBJECT_NAME(object_id),row_count from sys.dm_db_partition_stats
    whereOBJECT_NAME(object_id)='BigTable'but I need the row count that satisfies my where clause (i.e.: WHERE TypeName = 'ABC')

    It needs index to improve the performance. 
    - create index on typename column
    - create a indexed view to do the count in advance
    -partition on type name (although it's unlikely) then get count from the system tables...
    all those 3 solutions are about indexing.
    Regards
    John Huang, MVP-SQL, MCM-SQL, http://www.sqlnotes.info

Maybe you are looking for

  • Open links from other apps in Private Browsing

    When other Android apps open links in the default web browser, Firefox Mobile launches them in a normal new tab. How can I force these links to open in Private Browsing?

  • Transfering data through WiFi or GSM

    Hi there, I need some help here..I want to send and receive data through the wiFi or GSM..Is it possible??What module that I have to use?Please assist me...I need some idea how to start my project.. Please..

  • What is MacKeeper? and how do i get rid of it? please help

    i have had my mac for a while now and i have just noticed what appears to be a little burgalar at the top of the menu bar at the top of the screen. i was wondering if this was a virus or something i may have accidently downloaded? is it safe or do i

  • Refresh repository content - Failed! Help please.

    Hi, today I tried to refresh my repository via OVM Manager 3.0.3 (OVM Servers are also 3.0.3 version) and it fails with this error message: Job Construction Phase begin() Appended operation 'Repository refresh' to object '0004fb0000030000944aa10331c8

  • Support Ticket System

    Is there any source code available for Support Ticketing System ??