jframe

Java- How to set setToolTipText for JFrame

不羁的心 提交于 2019-12-02 09:42:29
问题 I would like to move the mouse over an image which was plotted on a JFrame using g2D.drawRenderedImag and display the x, y of that pixel at the tooltip text right next to mouse cursor. i.e: Graphics2D g2D = (Graphics2D)g; g2D.drawRenderedImage... I know how to read the x,y but don't know how to set setToolTipText for a JFrame. Can you guys help me please? I mean I can not do like this JFrame.setToolTipText !!!! 回答1: you can do componentName.setToolTipText("context"); for more information, you

What's Wrong WIth My Code involving JFrames

拟墨画扇 提交于 2019-12-02 09:37:45
It's Giving me an error saying that "The method setContentPane(Container) in the type JFrame is not applicable for the arguments (GamePanel)" Here is my Code: package main; import javax.swing.JFrame; public class Game { public static void main(String[] args){ JFrame window = new JFrame("Dragon Tales"); window.setContentPane(new GamePanel()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setResizable(false); } } I am following a tutorial exactly and his screen shows no errors at all. Your GamePanel class does not extend any Swing GUI component such as Container or one of its

java custom shaped frame using image [duplicate]

旧城冷巷雨未停 提交于 2019-12-02 09:36:04
This question already has an answer here: Image/Graphic into a Shape 3 answers i like to create a java jframe look like this image.i have already crated jframes with different shapes like triangles ,circles ,polygons and some crazy shapes .but the problem it's too hard[99% impossible ] to create shape like this image.so how can i make a jframe like this.i used this code for create shaped window.. setUndecorated(true); Polygon polygon = new Polygon(); polygon.addPoint(0, 0); polygon.addPoint(100,100); GeneralPath path = new GeneralPath(); path.append(polygon, true); setShape(path); now can i

JLabel only shows if initComponents() is deleted

你。 提交于 2019-12-02 09:35:36
MainFrame.java -JFrame public MainFrame() { initComponents(); Letters pl = new Letters(this); this.setContentPane(pl); this.setTitle("Preset Lessons"); this.pack(); } Letters.java -JPanel public Letters(JFrame frame) { initComponents(); JLabel label = new JLabel(); label.setText("Sample"); this.add(label); } if initComponents() in Letters.java is deleted thats the only time the JLabel will show up. How can I put the new JLabel to my existing JPanel? Contents of Letters.java's initComponents(); if I removed the iniComponents in the constructor it will create the JLabel. private void

Java full screen background color wont change?

百般思念 提交于 2019-12-02 09:07:56
问题 I have some code that creates a full screen icon in java and sets the background color to pink and the foreground color to red. However every time i run it, it never changes the background color to red but just keeps it see through. I put the code below. The main java: import java.awt.*; import javax.swing.*; @SuppressWarnings({ "serial" }) public class bob extends JFrame{ public static void main(String[] args) { DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);

Print JFrame with setVisible(false)

本小妞迷上赌 提交于 2019-12-02 08:59:44
问题 I create a Swing application with 2 JFrame windows and I want to 1st frame as main page. I set print button in 1st frame to print 2nd frame. How can I print the second frame with frame.setVisible(false); ? How can I solve it? I put my code below: package printuiwindow; /** * * @author Saravanan Ponnusamy */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.print.*; class PrintUIWindow implements Printable, ActionListener { JFrame frameToPrint; public int print

How to draw on top of an image in Java?

余生颓废 提交于 2019-12-02 08:51:41
I used JFrame to import and display an image, and used mousemotionlistener to detect the mouse clicks, and I want to be able to draw on top of the image. I want to be able to, if the user makes a click, make that pixel a certain color while preserving the rest of the image, however, I couldn't find out how to use Graphics to do so without deleting the rest of the image or opening a new window. public class Simple extends JFrame{ static ImageIcon icon; static JFrame myframe; static JLabel mylabel; static BufferedImage image = null; public static void main(String[] args) { try{ image = ImageIO

Drawing Canvas on JFrame

柔情痞子 提交于 2019-12-02 08:50:14
I'm trying to draw simple shapes with Canvas, in this class I've set the painting public class Game extends Canvas{ //FIELDS public int WIDTH = 1024; public int HEIGHT = WIDTH / 16 * 9; //METHODS public void start(){ Dimension size = new Dimension (WIDTH, HEIGHT); setPreferredSize(size); paint(null); } public void paint(Graphics g){ g.setColor(Color.GREEN); g.fillRect(0, 0, WIDTH, HEIGHT); g.setColor(Color.BLACK); g.fillOval(100, 100, 30, 30); } } And in this the Window public class MainW { public static void main(String[] args) { Game ga = new Game(); JFrame frame = new JFrame (); frame

Java - Custom shaped draggable JFrame

随声附和 提交于 2019-12-02 08:44:51
so I made a custom shaped JFrame using setShape(s); and I got it to look how I wanted the problem when you set the JFrame to be undecorated you can't drag the Frame with your mouse on the screen, so I tried to implement my own draggable frame, but it's not working as supposed to, here's the Frame class : package rt; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Polygon; import java.awt.Shape; import java.awt.event.MouseEvent; import java.io.IOException; import javax.swing.JFrame; import javax.swing.event.MouseInputAdapter; public class MyFrame extends

Is there a way to make JTextField for my address bar larger and curvier

混江龙づ霸主 提交于 2019-12-02 08:39:59
I'm making a browser just to practice my Java skills, is there a way to make my address bar which is a JTextField, larger instead of the swing's default value and also curvier. Here's my code. //imports of the GUI //import java.awt.*; //import java.awt.event.*; //import javax.swing.*; //import javax.swing.event.*; //import javax.swing.text.*; //import javax.swing.GroupLayout.*; //extends is to use the GUI class public class ReadFile extends JFrame { private JTextField addressBar; //to have the address bar private JEditorPane display; //display the html information //constructor //Set the frame