I need a JTextPane which has a header on top just like the one in a JTable. Basically I need a one row/column multiline JTable without having to go through all trouble crating renderes and editors. I tried adding a JLabel and JTextpane in a JPanel, but JLabel just isn't the same as a JTable Header and there is a gap between them.
Asked
Active
Viewed 169 times
-1
-
Subclassing a JLabel and reducing its preferredSize? – John Dvorak Oct 20 '12 at 08:56
-
@JanDvorak The visual styles aren't the same. I need it to look exactly like JTableHeader. – Igor Oct 20 '12 at 08:57
-
*"I need a JTextPane which has a header on top just like the one i a JTable."* ..Why? – Andrew Thompson Oct 20 '12 at 08:58
-
1Creating a stand-alone [JTableHeader](http://docs.oracle.com/javase/6/docs/api/javax/swing/table/JTableHeader.html)? – John Dvorak Oct 20 '12 at 09:01
-
@AndrewThompson Well, that's in the requirements, a text area which has a table like header. Raised JLabel just doesn't look good. – Igor Oct 20 '12 at 09:01
-
@Igor don't they mean functionally, not stylistically? – John Dvorak Oct 20 '12 at 09:02
-
@JanDvorak No, renaming the header text is the only functionality needed. Creating a JTableHeader and placing it where? It just doesn't show when you add it to a JPanel. It can probably be added to a JTable only. – Igor Oct 20 '12 at 09:05
1 Answers
1
not sure if is there big troubles for JTable, sure there could be only the issues with corners
put JPanel with JTextComponent(in JScrollPane) to the CENTER area, put JLabel/JTextField to the NORTH
change Opacity
get Color from JTableHeader (UIManager)
put there Borders
-
Well there is big troubles, because text needs to bestyled, and support hyperlink, and rendering styled text from the editor in a cell, is a big trouble. Thanks for your answer I think I'll give it a try. – Igor Oct 20 '12 at 09:09
-
Tried this and it doesn't work: - `JLabel header = new JLabel("Title");` - `header.setOpaque(true);` - `header.setBackground(UIManager.getColor(new JTableHeader()));` – Igor Nov 03 '12 at 21:03
-