preferredsize

BorderLayout only showing one object

ぃ、小莉子 提交于 2019-12-02 10:19:05
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 post actual images due to my low reputation statistic. Here is the code: main.java --> The main method

Size issues with JTabbedPane and fixed height content

旧街凉风 提交于 2019-12-01 23:56:12
While writing this question I have been able to find a way to get it to behave the way I wanted. Based on this , I am still posting the question as other people might face similar issues. I have the following issues with the sizing of a JTabbedPane used for content that stretches horizontally but has a fixed height. Both options for setTabLayoutPolicy() seem to alter the height of the content and won’t consistently display it at its preferred or minimum height. With the default WRAP_TAB_LAYOUT , the preferred size of the tab pane does not take into account whether the tabs are actually stacked

Components on the JPanel doesn't show

[亡魂溺海] 提交于 2019-12-01 12:07:11
I created a JPanel and i modify it a bit. I change it's background to gradient color here is the class. public class JGradientPanel extends JPanel { private static final int N = 32; private Color color1, color2; public JGradientPanel(Color color1, Color color2) { this.setBorder(BorderFactory.createEmptyBorder(N, N, N, N)); this.color1 = color1; this.color2 = color2; } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; //Color color1 = getBackground(); //Color color2 = color1.darker(); int w = getWidth(); int h = getHeight();

re-size JTable when useing Default table model

二次信任 提交于 2019-11-29 17:40:41
I have a JTable built using DefaultModel which is displayed in JPane but I would like to re-size the table to make it bigger. Could any one please explain how I could do that? I have tried the following code: TableColumnModel colsize = t1.getColumnModel(); for(int i=0; i<cols; i++){ colsize.getColumn(i).setPreferredWidth(200); } but it did not work. To size up the table#setPreferredSize(). table.setPreferredSize(new Dimension(500, 500)); To size up the columns table#getColumn(). table.getColumn(columnNames[0]).setPreferredWidth(100); table.getColumn(columnNames[1]).setPreferredWidth(400); I

JFrame isResizable(false) sizing issue

三世轮回 提交于 2019-11-29 14:12:05
I intended to make a JFrame with a ContentPanel of 600x600 and I wanted the JFrame to be not re-sizable. Inside this box, I Drew a 600x600 red-outlined rectangle to make sure that everything matched when i ran the program. Before restricting resizing for the JFrame, I set the size of my JFrame by doing: getContentPane().setPreferredSize( new Dimension(600,600)); pack(); And when I launched the program and the boundaries of my rectangle fit perfectly with the dimensions of the JFrame. However, when i added isResizable(false) into the equation, there seemed to be buffer of pixels between the

How to change JTable header height?

做~自己de王妃 提交于 2019-11-29 02:27:43
问题 Title explains the question. How can I easily do that? 回答1: import java.awt.*; import java.awt.event.*; import java.util.List; import java.util.Arrays; import javax.swing.*; import javax.swing.table.*; public class TableHeaderHeightTest { private static int HEADER_HEIGHT = 32; private JTable makeTable() { JTable table = new JTable(new DefaultTableModel(2, 20)); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); return table; } public JComponent makeUI() { JPanel p = new JPanel(new GridLayout(2

re-size JTable when useing Default table model

半腔热情 提交于 2019-11-28 09:56:06
问题 I have a JTable built using DefaultModel which is displayed in JPane but I would like to re-size the table to make it bigger. Could any one please explain how I could do that? I have tried the following code: TableColumnModel colsize = t1.getColumnModel(); for(int i=0; i<cols; i++){ colsize.getColumn(i).setPreferredWidth(200); } but it did not work. 回答1: To size up the table#setPreferredSize(). table.setPreferredSize(new Dimension(500, 500)); To size up the columns table#getColumn(). table

Set a column width of JTable according to the text in a header

不问归期 提交于 2019-11-28 05:39:01
问题 I need to get an appropriate table size according to a text in a header. It contains abbreviations of czech names of days like: "Po", "Út", "St", atc. but instead of this three dots are displayed. I have this code: width , height - max of all minimum row/column sizes allWidth , allHeight - should be the total width, height of the whole table //GET DIMENSION int width = 0; int height = 0; int allWidth, allHeight; for (int col = 0; col < table.getColumnCount(); col++) { TableColumn tableColumn

Large gap between JTables

↘锁芯ラ 提交于 2019-11-26 23:42:19
问题 The below is on the way to providing the results I am looking for, but unfortunately when this displays there is a large gap between tables on each page. It is so that I can only fit two of them on the screen per tab (with just two rows per table). private void display() { JFrame f = new JFrame("Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JLabel("Test")); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } class ResultsPanel extends JPanel implements