swing

Complex layout of multiple components

隐身守侯 提交于 2021-01-29 05:29:28
问题 I am designing a GUI where I have the components shown below. But in the second row, I would like to manage spaces between the components. For example, in the second row, I would like to fit both the JLabel "Move to time" and the JTextField without so much spacing. As I can see, right now MigLayout places the JTextField in line with the second component in the first row. Then, the JButton "Move" in the 2nd row should be aligned to the 2nd component in the first row. How do I achieve this?

Swing: process JFileChooser result after action?

痴心易碎 提交于 2021-01-29 05:11:15
问题 I want to use an Abstract action for JFileChooser buttons because there will be dozens of these. public class OpenFileAction extends AbstractAction { JFrame frame; JFileChooser chooser; OpenFileAction(JFrame frame, JFileChooser chooser) { super("Open..."); this.chooser = chooser; this.frame = frame; } public void actionPerformed(ActionEvent evt) { // Show dialog; this method does not return until dialog is closed chooser.showOpenDialog(frame); } }; Obviously I want to write the JFileChooser

Swing: process JFileChooser result after action?

大憨熊 提交于 2021-01-29 05:10:14
问题 I want to use an Abstract action for JFileChooser buttons because there will be dozens of these. public class OpenFileAction extends AbstractAction { JFrame frame; JFileChooser chooser; OpenFileAction(JFrame frame, JFileChooser chooser) { super("Open..."); this.chooser = chooser; this.frame = frame; } public void actionPerformed(ActionEvent evt) { // Show dialog; this method does not return until dialog is closed chooser.showOpenDialog(frame); } }; Obviously I want to write the JFileChooser

Layout - Relative to screensize

半腔热情 提交于 2021-01-29 04:41:19
问题 So I am a computer science student and I've finished my first year. I wanted to create a simple program and I realized that I am so tired of using no layout; this.setLayout(null); It is so tiresome to add bounds to every single component. Well, I have been using JPanel components and GridLayout a lot, which have made my work a bit easier. But I am tired of it. I care very much about the look of the GUI I make and use almost half the time programming to make the GUI look good before I start

Swing Timer not working as planned

ⅰ亾dé卋堺 提交于 2021-01-29 04:28:17
问题 I Think this is a Timer issue, first time ive used them and i feel like im doing it wrong. I have a method that for testings sake, input 6 images and with the help of a timer paints them to a JPanel: private void drawDice(Graphics2D g2d) throws IOException, InterruptedException { image = ImageIO.read(getClass().getResourceAsStream("/1.png")); m_dice.add(image); image = ImageIO.read(getClass().getResourceAsStream("/2.png")); m_dice.add(image); image = ImageIO.read(getClass()

java.lang.StackOverflowError between two classes

萝らか妹 提交于 2021-01-29 03:54:45
问题 I'm trying to create a JFrame in one class and adding a JPanel to it in my main class, is this not possible? This is my Main class public class Main { JPanel p; JLabel lbl1; public static void main(String[] args) { new Main(); } Main() { new Window(); JPanel p = new JPanel(); JLabel lbl1 = new JLabel("Hello"); p.add(lbl1); } } And the Window class public class Window extends Main { Window() { JFrame frame = new JFrame(); frame.setSize(400, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON

How to display two canvas in a JFrame java

这一生的挚爱 提交于 2021-01-29 03:50:56
问题 I recently have a requirement to display a word file within a JFrame . With this link I was able to achieve what I want (Open MS documents into JFrame). What i need is to display a word file and a pdf file side by side within a JFrame. In the link mentioned above, the word file was displayed in a JFrame via a Canvas from SWT. I would like to know: Whether it is possible to add two canvases to a single JFrame . If not, is it possible to display a word document or a PDF file in a JPanel (since

Illegal static declaration in inner class while using ActionListener

混江龙づ霸主 提交于 2021-01-29 03:08:12
问题 I'm trying to write a basic calculator GUI program for homework. I'm trying to define a variable for each button pressed on the calculator, and make a calculation when all the variables are declared. Right now, it's only able to add/subtract/divide/multiply two numbers 0-9, but I want to make sure I can get that working before expanding it. My problem is that I get the error code, "Illegal static declaration in inner class Calculator.sign". I'm wondering how I can get past this error. Thanks

Java swing metal JButton focus border size

血红的双手。 提交于 2021-01-29 03:07:02
问题 If I set Metal theme for Swing GUI, JButton border is painted around the whole button, but focus border is painted only around JButton's text and icon, so if text size is smaller than button size, the border appears inside button. Most replies to this problem simply suggest to disable global focus border painting by UIManager.getLookAndFeelDefaults().put("Button.focus", new ColorUIResource(new Color(0, 0, 0, 0))); or per-button by jButton.setFocusPainted(false); But I actually want focus

Java swing metal JButton focus border size

a 夏天 提交于 2021-01-29 03:03:26
问题 If I set Metal theme for Swing GUI, JButton border is painted around the whole button, but focus border is painted only around JButton's text and icon, so if text size is smaller than button size, the border appears inside button. Most replies to this problem simply suggest to disable global focus border painting by UIManager.getLookAndFeelDefaults().put("Button.focus", new ColorUIResource(new Color(0, 0, 0, 0))); or per-button by jButton.setFocusPainted(false); But I actually want focus