awt

Programmatically swap two JPanels in JFrame

一曲冷凌霜 提交于 2019-12-08 01:42:57
问题 I am trying to accomplish the above functionality, and am having little success. I am using GridLayout with 2 columns and 2 rows to show the user a puzzle-like game, where there are 4 (200x200 pixel) JPanels (3 colored, 1 default bgColor) which fill the whole contentPane. Clicking on a colored panel resolves in an assessment if the panel is next to the gray panel. If so, they should swap. I have accomplished every step to the last one, where they swap. Here's the code: public class MainClass

java UnsatisfiedLinkError awt.image

邮差的信 提交于 2019-12-07 23:55:57
问题 I have a program that makes use of the following method to get a scaled instance of an image icon: public ImageIcon createScaledImageIcon(String filename) { ImageIcon icon = new ImageIcon(filename); Image image = icon.getImage().getScaledInstance(cardWidth, cardHeight, Image.SCALE_SMOOTH); icon.setImage(image); return icon; } I don't know if it's the source of the problem or not. But i get the following error messages: Exception in thread "Image Fetcher 0" java.lang.UnsatisfiedLinkError: sun

FontMetrics setFont?

好久不见. 提交于 2019-12-07 21:44:57
问题 I am making a program in which I need to set the Font inside a FontMetrics object. I have already created the fontmetrics before, but now I don't have access to the Graphics object anymore. Yet, I want to change the font inside the FontMetrics, that is, create a new FontMetrics, with a new Font, but using the same Graphic context. I could make the Graphics avaliable, but it would take a lot of time and it wouldn't make sense at all to do so. Would anyone know an easier way to it? It seens so

Why doesn't my repaint work?

强颜欢笑 提交于 2019-12-07 16:06:46
问题 I'm stuck with a problem considering my Display class, which extends Canvas. A single thread is running within the very same class. In this thread, the repaint method is called. However, while the thread works fine, the paint method is never called! Here's my code (I left out everything unrelated): package display; public final class Display extends Canvas implements Runnable { private static final long serialVersionUID = 1L; private Frame frame; private GraphicsEnvironment ge; private

How to make a Round Rectangle JTextField?

懵懂的女人 提交于 2019-12-07 15:02:36
问题 I want to make a round rectangle JTextField. I write a sub class of AbstractBorder to realize it.But I run into some problems. My requirement is: What I get is: My code is : import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing

Canvas object is not displaying, but location is updating correctly in Java Applet

安稳与你 提交于 2019-12-07 12:19:14
问题 My basic bouncing ball Applet should have a ball moving around according to the values in loc variable, but nothing shows up. Printing out loc shows that the numbers/math behind moving it around and bouncing off boundaries is indeed working as it should, but nothing shows up. Looking at examples online I didn't see why my drawing/painting code wasn't working as intended. Here's what I have, issues are probably focused about halfway down where the Ball object is. I posted most of the program

Most up-to-date version of the java “Clearthought” TableLayout project

一笑奈何 提交于 2019-12-07 12:16:28
问题 What is the status of the java "Clearthought" TableLayout project? is it still being maintained? what is its most up-to-date website? old page: http://www.clearthought.info/sun/products/jfc/tsc/articles/tablelayout/ not working: https://tablelayout.dev.java.net/ maven repository with 2005 version: http://mvnrepository.com/artifact/tablelayout/TableLayout/20050920 any other more up-to-date page? 回答1: It seems that the author abandoned the project. So I decided to bring it back to life: change

Java font size from width

五迷三道 提交于 2019-12-07 10:46:56
问题 I'm looking for a way to infer a Java AWT Font size from a width. For example, I know I want to write 'hello world' within 100 pixels. I know I'm using the font "Times", in style Font.PLAIN , and I want to get the font size that fits the best with my given width of 100 pixels. I know I could calculate it in a loop (something like while(font.getSize() < panel.getWidth() ), but to be honest I don't find it very elegant. 回答1: You can get the rendered width and height of a string using the

Java swing 1.6 Textinput like firefox bar

此生再无相见时 提交于 2019-12-07 10:20:54
问题 I would like to create a textwidget/component wich looks like the firefox address bar. I mean a Textfield wich allows me to place little Buttons inside the field (e.g. cancel/reload/...) I tried customizing a JLayeredPane, by creating a custom layout manager which maximizes the Textfield, and places the remainder from right to left. My problem is that this gave painting issues, I would not always see the items I added over the textfield. This might be Jython related, I try suppling java.lang

Modifying a JFrame from within a Listener [duplicate]

狂风中的少年 提交于 2019-12-07 06:04:29
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to call setUndecorated() after a frame is made visible? How should I make a JFrame be undecorated when unfocused and decorated when focused? Here's my code: import java.awt.event.*; import javax.swing.*; public class Test extends JFrame { public Test() { setSize(100, 50); addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { setUndecorated(false); System.out.println("Hi!