preferredsize

Automatically adjust Jtable Column to fit content

我是研究僧i 提交于 2019-12-09 17:01:23
问题 I am trying to match the JTable column width depending on the data inside. My Code: for(int column = 0; column < gui.testsuiteInfoTable.getColumnCount(); column ++){ int width =0; for (int row = 0; row < gui.testsuiteInfoTable.getRowCount(); row++) { TableCellRenderer renderer = gui.testsuiteInfoTable.getCellRenderer(row, column); Component comp = gui.testsuiteInfoTable.prepareRenderer(renderer, row, column); width = Math.max (comp.getPreferredSize().width, width); System.out.println(width);

How to set a size for JMenuItem?

蹲街弑〆低调 提交于 2019-12-07 15:29:36
问题 As you can see, it's ugly to have these kind of JMenuItem s. The width of the menu items is quite small. Here is the code: JMenu menuOne=new JMenu("MenuOne"); JMenu menuTwo=new JMenu("MenuTwo"); JMenu menuThree=new JMenu("MenuThree"); JMenu menuFour=new JMenu("MenuFour"); JMenuBar mbar=new JMenuBar(); //add the menu to menubar mbar.add(menuOne); JMenuItem OneItOne=new JMenuItem("1"); JMenuItem OneItTwo=new JMenuItem("2"); menuOne.add(OneItOne); menuOne.addSeparator(); menuOne.add(OneItTwo);

Set size of JTable in JScrollPane and in JPanel with the size of the JFrame

廉价感情. 提交于 2019-12-06 11:21:41
I want the table with the same width as the frame and also when I resize the frame the table need to be resized too. I think setSize() of JTable doesn't work correctly. Can you help me? import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingUtilities; public class Main extends JFrame { public Main() { setSize(400, 600); String[] columnNames = {"A", "B", "C"}; Object[][] data = { {"Moni", "adsad", 2}, {"Jhon", "ewrewr", 4}, {"Max", "zxczxc", 6} }; JTable table = new JTable(data, columnNames)

How to set a size for JMenuItem?

核能气质少年 提交于 2019-12-06 01:59:42
As you can see, it's ugly to have these kind of JMenuItem s. The width of the menu items is quite small. Here is the code: JMenu menuOne=new JMenu("MenuOne"); JMenu menuTwo=new JMenu("MenuTwo"); JMenu menuThree=new JMenu("MenuThree"); JMenu menuFour=new JMenu("MenuFour"); JMenuBar mbar=new JMenuBar(); //add the menu to menubar mbar.add(menuOne); JMenuItem OneItOne=new JMenuItem("1"); JMenuItem OneItTwo=new JMenuItem("2"); menuOne.add(OneItOne); menuOne.addSeparator(); menuOne.add(OneItTwo); mbar.add(menuTwo); mbar.add(menuThree); mbar.add(menuFour); setJMenuBar(mbar); Simply adding some blanks

Resize JTable to fit number of rows

不羁岁月 提交于 2019-12-04 07:01:24
问题 I have a JTable which would be populated dynamically and I want the table to always resize to fit the number of rows. I don't want any scrolling because the table is in a panel and the contents of the panel needs to be printed. I've tried this: Dimension d = itemsTable.getPreferredSize(); //scrollPane.setPreferredSize(new Dimension(d.width,itemsTable.getRowHeight()*itemsTable.getRowCount()+10)); itemsTable.setPreferredScrollableViewportSize(new Dimension(d.width,itemsTable.getRowHeight()

Automatically adjust Jtable Column to fit content

孤街浪徒 提交于 2019-12-04 03:44:11
I am trying to match the JTable column width depending on the data inside. My Code: for(int column = 0; column < gui.testsuiteInfoTable.getColumnCount(); column ++){ int width =0; for (int row = 0; row < gui.testsuiteInfoTable.getRowCount(); row++) { TableCellRenderer renderer = gui.testsuiteInfoTable.getCellRenderer(row, column); Component comp = gui.testsuiteInfoTable.prepareRenderer(renderer, row, column); width = Math.max (comp.getPreferredSize().width, width); System.out.println(width); } TableColumn col = new TableColumn(); col = gui.testsuiteInfoTable.getColumnModel().getColumn(column);

Components on the JPanel doesn't show

假如想象 提交于 2019-12-04 02:15:35
问题 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 =

how to set the size of JPanel in java

浪尽此生 提交于 2019-12-02 19:00:09
问题 I have a JPanel in my java code and I want to set its size, I have used JPanel.setSize(500,500); and JPanel.setSize(new Dimension(500,500)); but both are not working. Please tell how I can set the size of JPanel? 回答1: Most Swing layout managers respect a component's preferredSize and not its size. You could call setPreferredSize(new Dimension(500, 500)) , but this can be overridden later in your code, and can lead to an inflexible GUI. Better to override the JPanel's getPreferredSize() method

how to set the size of JPanel in java

。_饼干妹妹 提交于 2019-12-02 12:38:44
I have a JPanel in my java code and I want to set its size, I have used JPanel.setSize(500,500); and JPanel.setSize(new Dimension(500,500)); but both are not working. Please tell how I can set the size of JPanel? Most Swing layout managers respect a component's preferredSize and not its size. You could call setPreferredSize(new Dimension(500, 500)) , but this can be overridden later in your code, and can lead to an inflexible GUI. Better to override the JPanel's getPreferredSize() method and return a calculated Dimension that works best in all situations. For example: import java.awt.Color;

Sizing a JScrollPane in a JTabbedPane in a JFrame

a 夏天 提交于 2019-12-02 11:44:43
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 of the maximum sized component you add to it. Because of this my JScrollPane does not show up at all. I