Unable to instantiate Java Font class

When i attempt to create the Java font my my excel cell I get an error from Eclipse saying "Cannot instantiate the type Font"

Why can't I instantiate the class?

private  void createCell(Workbook wb, Row row, int i, short halign, short valign, int value) {
            CreationHelper ch = wb.getCreationHelper();
            DataFormat format = wb.createDataFormat();
            Cell cell = row.createCell(i);
            cell.setCellValue(value);
            CellStyle cellStyle = wb.createCellStyle();


            cellStyle.setDataFormat(format.getFormat("###0"));
            Font myFont = new Font("Courier", Font.COLOR_RED, 12);
            cellStyle.setFont(myFont);
            cellStyle.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
            cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
            //cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
            //cellStyle.setFillPattern(CellStyle.BORDER_THICK);


            cellStyle.setAlignment(halign);
            cellStyle.setVerticalAlignment(valign);

            cell.setCellStyle(cellStyle);

      }
Christopher ScheneSystem Engineer/Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Make sure it's java.awt.Font and not something else
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
cellStyle.setFont(myFont); won't accept an object of type java.awt.Font: It wants  org.apache.poi.ss.usermodel.Font
CEHJCommented:
https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Font.html cannot be instantiated - it's an interface. You need one of its implementing classes (see that link)
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

zzynxSr. Software engineerCommented:
It will be more something like:

HSSFFont myFont=wb.createFont();
myFont.setColor(HSSFColor.RED.index);
myFont.setFontHeightInPoints((short)12);
cellStyle.setFont(myFont);

Open in new window


See this page for examples

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
I found that this works after much trial and error

      XSSFFont myFont= wb.createFont();
            myFont.setFontHeightInPoints((short)10);
            myFont.setFontName("Arial");
            myFont.setColor(IndexedColors.RED.getIndex());
            myFont.setBold(true);
            myFont.setItalic(false);
            cellStyle.setFont(myFont);
zzynxSr. Software engineerCommented:
All right, so...? (Time to close this one I would think)
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
Sorry: completely spaced and forgot I left this open. :-(
zzynxSr. Software engineerCommented:
Thanx 4 axxepting
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.