It works fine if I add enough line numbers. Where with "enough" I mean, more than the height can handle.
Added a red border around the lineNumberPanel:
Tour de java.png 75.94K
40 downloadsBut I don't want to have more line numbers than needed. Partially because it creates an unneeded scrollbar, but also because it's prettier if there are as many line numbers as there are lines.
But when I do that, then there's a vertical-align = center going on...
(I think i'm "stuck" with a gridbaglayout, because my 1st line number needs to be a bit lower than the top, I as well need 1 extra pixel to match the correct height at every line item (or increase font size by 1, which I don't want to do))
Vertical align img:
Tour de java_exact_lines.png 73.45K
56 downloadsAnyone has an idea to make it align to the top?
Line number code:
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
for(int i=0 ; i<lines ; i++){
c.gridy = i;
if(i ==0){
c.insets = new Insets(11,0,0,0);
} else {
c.insets = new Insets(1,0,0,0);
}
JLabel number = new JLabel((i + 1) + "");
number.setFont(mainFont);
lineNumbers.add(number, c);
}
Oh, if it matters, the jpanel with gridbaglayout(line number panel) is inside a BorderLayout jpanel at the WEST.


Sign In
Create Account


Back to top









