Button and Textbox alignment in a jtable cell

不打扰是莪最后的温柔 提交于 2019-12-11 06:46:46

问题


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:


  • JPanel has implemented FlowLayout then to pretty accepting the PreferredSize came from its childs,

  • notice everything depends of your TableCellRenderer and TableCellEditor too

  • my view, my example



来源:https://stackoverflow.com/questions/12622585/button-and-textbox-alignment-in-a-jtable-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!