# Problem formatting java code in my latex document (overshooting the page)

My code is being formatted in a way that makes it drift off the page when it's too long rather than just jump to a new line. I have tried lots of different things, pasted all kinds of examples from the answers on here for code formatting but none of it seems to stop the lengthy bits from going over. I don't know why it is happening so I am at a loss on how to fix it.

Here is an example of the worst offending (it just goes right out the page for no good reason)

 \documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{changepage}
\usepackage{framed}
\usepackage{tikz}
\usepackage{listings}
\usepackage{bbding}

\lstset{backgroundcolor=\color{LightSteelBlue!20},
frame=trbl,
rulecolor=\color{black!30},
xrightmargin=7pt}

\begin{document}
\begin{lstlisting}

public void write(double step, double max, PrintWriter locusOutFile, PrintWriter impOutFile) throws IOException {

\end{lstlisting}
\end{document}


-
You haven't used breaklines=true – David Carlisle Dec 19 '12 at 16:02

As noted in comment on the question you were missing breaklines=true

 \documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{changepage}
\usepackage{framed}
\usepackage{tikz}
\usepackage{listings}
\usepackage{bbding}

\lstset{breaklines=true,backgroundcolor=\color{LightSteelBlue!20},
frame=trbl,
rulecolor=\color{black!30},
xrightmargin=7pt}

\begin{document}
\begin{lstlisting}

public void write(double step, double max, PrintWriter locusOutFile, PrintWriter impOutFile) throws IOException {

\end{lstlisting}
\end{document}

-
Genius! That worked. – Magpie Dec 19 '12 at 16:06
I just searched for long in the listings manual. – David Carlisle Dec 19 '12 at 16:08
why did you search for long? – Magpie Dec 19 '12 at 16:14
first few letters of "long line" lucky guess? But really most verbatim listing packages will not line break by default just like a pre in html does not (as you see in your question) – David Carlisle Dec 19 '12 at 16:19
@cmhughes note added as requested – David Carlisle Dec 19 '12 at 17:04