preferredsize

JTable: Adding one to a JPanel, and it not displaying itself

ぃ、小莉子 提交于 2019-12-24 12:43:04
问题 It's Monday morning where I am, which means it's time for me to fail at Java Swing! But in all seriousness, I cannot figure out why my dynamically created JTable refuses to show itself once added to a JPanel on a JFrame, and would greatly appreciate any help in isolating this troublesome problem. As you can see from the code, I've called a dozen different methods, but can't seem to get the right one to get it to display...perhaps I am missing one? /* * To change this template, choose Tools |

Keep BoxLayout From Expanding Children

不打扰是莪最后的温柔 提交于 2019-12-23 21:28:56
问题 I want to stack some JComponents vertically inside a JPanel so they stack at the top and any extra space is at the bottom. I'm using a BoxLayout. The components will each contain a JTextArea that should allow the text to wrap if necessary. So, basically, I want the height of each of these components to be the minimum necessary for displaying the (possibly wrapped) text. Here's a contained code example of what I'm doing: import javax.swing.*; import java.awt.*; public class TextAreaTester {

JDesktopPane preferred size set by content

吃可爱长大的小学妹 提交于 2019-12-21 07:55:54
问题 I have been trying to tame JDesktopPane to work nicely with a resizable GUI & a scroll pane, but am having some troubles doing so. It seems that unless the drag mode is outline, the desktop pane will not resize as expected (when an internal frame is dragged beyond the edge of the desktop pane) & therefore not produce scroll-bars. Am I doing something very silly in this source? Have I missed a far better approach? import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax

Sizing a JScrollPane in a JTabbedPane in a JFrame

馋奶兔 提交于 2019-12-20 07:10:00
问题 I understand from this post Don't Set sizes on a JComponent that you dont set preferred sizes on any component and instead let the layout manager do this for you. My question is, I have a JPanel that I put into a JTabbedPane into a JFrame like this JFrame frame=new JFrame(); JTabbedPane pane=new JTabbedPane(); pane.addTab("Tab 1",new JScrollPane(getJPanel1())); pane.addTab("Tab 2",new JScrollPane(getJPanel2())); frame.setContentPane(pane); Now in this case the JTabbedPane will take the size

BorderLayout only showing one object

限于喜欢 提交于 2019-12-20 06:47:13
问题 I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that. So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: http://prntscr.com/3m5ek6 I can't

BorderLayout only showing one object

≡放荡痞女 提交于 2019-12-20 06:28:03
问题 I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that. So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: http://prntscr.com/3m5ek6 I can't

Set Column Width of JTable by Percentage

自作多情 提交于 2019-12-18 13:36:02
问题 I need to assign a fixed width to a few columns of a JTable and then an equal width to all the other columns. Suppose a JTable has 5 columns. The first column should have a width of 100 and the second one a width of 150. If the remaining width of the JTable is 600 after setting the width of the two columns, I'd like to evenly split it among the other three columns. The problem is table.getParent().getSize().width is often 0, even if it is added to the JFrame and visible, so I can't use it as

Enabling auto resize of JTable only if it fit viewport

这一生的挚爱 提交于 2019-12-18 04:36:08
问题 I need to create a JTable inside JScrollPane with resizeable columns (when user increase column width - horizontal scrollbar appears). For this I have use table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); . Also, when viewport is wide enough to contain entire table - columns should stretch to fill viewport width. To accomplish this I have override getScrollableTracksViewportWidth() method of JTable class as follow: @Override public boolean getScrollableTracksViewportWidth() { return

BorderLayout setSize issue

微笑、不失礼 提交于 2019-12-13 00:25:27
问题 Before you come with GridBagLayout suggestions, I've tried that but I couldn't get it to work. I want a frame with the size 800 x 800 and with a center panel of 600x600. Right now, when I run it the center panel is 600x578. Can someone tell me where it goes wrong? It's just 22 pixels. public void createPlayground() { JFrame frame = new JFrame("ForFun Maze"); frame.setSize(WIDTH, HEIGHT); frame.setResizable(false); frame.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel();

JTextArea no scroll bar

邮差的信 提交于 2019-12-12 20:24:26
问题 private JPanel contentPane; public Driver() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 867, 502); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); textArea.setBounds(10, 11, 831, 393); JScrollPane scroll = new JScrollPane(textArea); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR