问题
I have a table which has both button and text box in some cells. Now I am able to put both the components in the table cell. Thanks for OscarRyz's code. Now my problem is I have to align these components such that the button is to extreme right of the cell and text box should start from the extreme left of the cell to the start of the button. (In simple, they should be adjacent to each other and occupy entire cell.) How can I align them inside the cell?
Currently it looks like this,
But what I was looking is for the view something like this,
I have looked at Component Border code but can't figure out how to use it for the table.
Any help will be appreciated.
回答1:
A JPanel with BorderLayout where you put the JTextField in the BorderLayout.CENTER and the JButton in the BorderLayout.EAST should do it.
And for future reference: bookmark the Visual guide to layout managers if you are looking for a LayoutManager
回答2:
JPanelhas implementedFlowLayoutthen to pretty accepting thePreferredSizecame from its childs,notice everything depends of your
TableCellRendererandTableCellEditortoomy view, my example
来源:https://stackoverflow.com/questions/12622585/button-and-textbox-alignment-in-a-jtable-cell