473,410 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Custom Painting

176 100+
Hello guys. I was wondering if it is possible to perform custom painting in a GUI window using C++. In Java you can do this by using the following code:
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.SwingUtilities;
  2. import javax.swing.JFrame;
  3. import javax.swing.JPanel;
  4. import javax.swing.BorderFactory;
  5. import java.awt.Color;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8.  
  9. public class SwingPaintDemo2 {
  10.  
  11.     public static void main(String[] args) {
  12.         SwingUtilities.invokeLater(new Runnable() {
  13.             public void run() {
  14.                 createAndShowGUI(); 
  15.             }
  16.         });
  17.     }
  18.  
  19.     private static void createAndShowGUI() {
  20.         System.out.println("Created GUI on EDT? "+
  21.         SwingUtilities.isEventDispatchThread());
  22.         JFrame f = new JFrame("Swing Paint Demo");
  23.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
  24.         f.add(new MyPanel());
  25.         f.pack();
  26.         f.setVisible(true);
  27.     }
  28. }
  29.  
  30.  
  31. class MyPanel extends JPanel {
  32.  
  33.     public MyPanel() {
  34.         setBorder(BorderFactory.createLineBorder(Color.black));
  35.     }
  36.  
  37.     public Dimension getPreferredSize() {
  38.         return new Dimension(250,200);
  39.     }
  40.  
  41.     public void paintComponent(Graphics g) {
  42.         super.paintComponent(g);       
  43.  
  44.         // Draw Text
  45.         g.drawRect(120, 100, 125, 50);
  46.     }  
  47. }
This would draw a simple rectangle on the screen. So can you do this in C++?
Jun 1 '08 #1
1 1309
oler1s
671 Expert 512MB
C++ has no concept of a GUI. How you handle a GUI and drawing in C++ depends entirely on the GUI API in question.
Jun 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Steve | last post by:
I have created a transparent custom drawn treeview in c#(using lots of native code as well) that has a bitmap for its background. As well as that, I have created a custom highlight that is a...
3
by: Bill Merrill | last post by:
I'm having a problem with a custom-painted panel. Upon resize, it's invalidated, and redrawn properly. It's also double-buffered so there's no flicker. When I resize the control during...
5
by: Alien | last post by:
I have a hex editor-type class that extends UserControl and paints its data to a PictureBox. Basically the problem is that repainting it takes usually between 60 and 80ms, which may seem pretty...
11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
2
by: SpotNet | last post by:
Hi Newsgroup, I've been creating (almost done) Common Dialog class libraries (under one name space) with highly customisable common dialogs. With my ColorDialog I am able to completely hide...
1
by: David Sobey | last post by:
Hi I'm making a custom component using GDI+, a calendar grid thingy. I paint the grid and numbers in my overrided OnPaint. However, when i go to paint other things at other times in other...
0
by: J Rico | last post by:
Hi, I'm having a problem with some code we're writting. Our customer doesn't like windows forms style painting, so their designer has created a skin and we have added it. There are many ways in...
3
by: TheSteph | last post by:
Hi, I've made a CustomPanel derived from the Panel class. How can I set my own size of the "client area" of that CustomPanel ? ("client area" = Size of the rectangle in which one can drop...
1
by: John J. Hughes II | last post by:
I am trying to create a custom DataGridViewCell which is "NOT" derived from DataGridViewTextBoxColumn. The painting works fine but I am unable to get the control into edit mode. Do I need to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.