“Could not find the main class” error when running jar exported by Eclipse

Verify that you can start your application like that: java -cp myjarfile.jar snake.Controller I just read when I double click on it – this sounds like a configuration issue with your operating system. You’re double-clicking the file on a windows explorer window? Try to run it from a console/terminal with the command java -jar myjarfile.jar … Read more

Setting minimum size limit for a window in java swing

The documentation tells me, that this behavior is platform dependent. Especially, since the following example code works for me as desired in Windows Vista: import java.awt.Dimension; import javax.swing.JFrame; public class JFrameExample { public static void main(String[] args) { JFrame frame = new JFrame(“Hello World”); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setMinimumSize(new Dimension(100, 100)); frame.setVisible(true); } }

Can I add a component to a specific grid cell when a GridLayout is used?

No, you can’t add components at a specific cell. What you can do is add empty JPanel objects and hold on to references to them in an array, then add components to them in any order you want. Something like: int i = 3; int j = 4; JPanel[][] panelHolder = new JPanel[i][j]; setLayout(new GridLayout(i,j)); … Read more

How to create on click event for buttons in swing?

For that, you need to use ActionListener, for example: JButton b = new JButton(“push me”); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //your actions } }); For generating click event programmatically, you can use doClick() method of JButton: b.doClick();

How to center in JTable cell a value?

You need to customize the renderer. To center the first column you can do: DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment( JLabel.CENTER ); table.getColumnModel().getColumn(0).setCellRenderer( centerRenderer ); To center all columns with String data you can do: DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment( JLabel.CENTER ); table.setDefaultRenderer(String.class, centerRenderer);

Centering a JLabel in a JPanel

Set GridBagLayout for JPanel, put JLabel without any GridBagConstraints to the JPanel, JLabel will be centered example import java.awt.*; import javax.swing.*; public class CenteredJLabel { private JFrame frame = new JFrame(“Test”); private JPanel panel = new JPanel(); private JLabel label = new JLabel(“CenteredJLabel”); public CenteredJLabel() { panel.setLayout(new GridBagLayout()); panel.add(label); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(panel); … Read more

How to wrap lines in a jtable cell?

The problem is that the height of rows in JTable is fixed, so it’s not just a matter of having a renderer that wraps; I’m not sure why it doesn’t, but if it did, the wrapped text would be cropped – or maybe that’s exactly what you’re seeing. To adjust row heights, you need to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)