jack
jack

Reputation: 73

Filling a combobox with list of available fonts in JSP

I have a JSP file with an combobox in it. THe combobox will list all available fonts in system. How can I do that? Thanks.

Upvotes: 0

Views: 64

Answers (1)

hityagi
hityagi

Reputation: 5256

This should do the trick :

<%@page import="java.awt.Font"%>
<%@page import="java.awt.GraphicsEnvironment"%>
<html>
    <body>
    <select>
        <%
         GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] fonts = e.getAllFonts(); // Get the fonts
        for (Font f : fonts) {
          %>
            <option><%=f.getFontName() %></option>
          <% 
        }
        %>
        </select>
    </body>
</html>

Upvotes: 1

Related Questions